Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I am trying to make a part only give a tool once when I touch it, can you help me with this error?

Asked by 7 years ago

But when I touch the part, it gives multiple of the same tool at once, can you help me with this?

Here is the script I used:

script.Parent.Touched:Connect(function(hit)

if hit.Parent.Humanoid then
plr = game.Players:GetPlayerFromCharacter(hit.Parent)
local gravity = game.ReplicatedStorage.Gun:Clone()
gravity.Parent = plr.Backpack

end

end)

1 answer

Log in to vote
0
Answered by
UgOsMiLy 1074 Moderation Voter
7 years ago

Debounce.

local debounce = false
script.Parent.Touched:Connect(function(hit)
    if hit.Parent.Humanoid then
        if debounce == true then return end
        debounce = true
        plr = game.Players:GetPlayerFromCharacter(hit.Parent)
        local gravity = game.ReplicatedStorage.Gun:Clone()
        gravity.Parent = plr.Backpack
        wait(0.7)
        debounce = false
    end
end)

Read more about debounce

0
Thanks for the help HimoutoUmaruDomaChan 20 — 7y
0
But how do you get it to do it forever, I'm trying to make the baseplate give the tool, but it doesn't last forever, and will this work for other people as well? HimoutoUmaruDomaChan 20 — 7y
0
I'm not really sure what you mean by that. It should work for everyone, but if many players are on the baseplate at the same time, it might not. What you could try is making it so that it will give every player the tool, but only once per player. UgOsMiLy 1074 — 7y
Ad

Answer this question