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

How to use a touch event to spawn only one clone of an object?

So I've been toying with Studio for a couple weeks now and learned how to make buttons that the player model can stand on to spawn objects into the workspace. I ran into a problem where I spawn multiple copies of the object. It seems to be spawning one copy for every body part that makes contact with the button. Any ideas on how I can only make it spawn one per character with a cooldown instead?

game.Workspace.JeepSpawnPad.Touched:Connect(function(hit)
	if game.Players:GetPlayerFromCharacter(hit.Parent) then
		game.ServerStorage.Jeep:Clone().Parent = workspace
	end
end)

1 answer

✓ Accepted answer

Add debounce.

local debounce = false
game.Workspace.JeepSpawnPad.Touched:Connect(
    function(hit)
        if debounce == false then
            if game.Players:GetPlayerFromCharacter(hit.Parent) then
                debounce = true
                game.ServerStorage.Jeep:Clone().Parent = workspace
            end
        end
    end
)

1 comment

0

Thanks for the help! Going to fiddle with this and figure out how to make the button reusable!

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