我有这个脚本,当我运行它时,它可以工作,但是,在所有玩家上,我只希望它适用于触摸它的人。
代码:
local CooldownTime = 0.15
local Debounce = false
game.Players.PlayerAdded:Connect(function(plr)
script.Parent.Touched:Connect(function()
if Debounce == false then
Debounce = true
if plr.leaderstats.Cash.Value >= 125 then
if plr.leaderstats.EnhancerMulti.Value <= 2 then
plr.leaderstats.Multiplier.Value = plr.leaderstats.Multiplier.Value +1
else
plr.leaderstats.Multiplier.Value = plr.leaderstats.Multiplier.Value + (plr.leaderstats.EnhancerMulti.Value)
end
plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value == 0
wait(CooldownTime)
Debounce = false
else
Debounce = false
end
end
end)
end)
我试过了,我希望它只适用于一个玩家,而不是所有玩家。
对于每个加入的玩家,您都将回调添加到该部分,该部分执行该玩家的代码。
假设有 2 个玩家加入。然后你有 2 个回调。玩家 1 现在接触了物体,物体触发了所有 2 个回调,因此对两个玩家都是如此。
不是为每个玩家添加回调,而是添加一个回调并使用触摸部分(第一个也是唯一的参数)来确定玩家:https://create.roblox.com/docs/reference/engine/classes/BasePart#感动
当玩家 1 现在触摸物体时,唯一的回调会触发并为您提供玩家。