Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

3 comments

0

Thanks for the help

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?

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.