So this question links to my first one. I sort of figured out how to add a new model on button touch, but now, whenever I touch the block, the car keeps on being cloned, and crashes the game. Can you please help???
local car = game.Workspace.car function clone() local yes = car:Clone() yes.Parent = game.Workspace yes.Position = Vector3.new(300.905, 6.5, -275.073) end script.Parent.Touched:Connect(clone)
Thank you!
a simple debounce should do the trick!
local car = game.Workspace.car local debounce = false function clone() if not debounce then debounce = true local yes = car:Clone() yes.Parent = game.Workspace yes.Position = Vector3.new(300.905, 6.5, -275.073) wait(5) -- Set this to how long the debounce should be debounce = false end end script.Parent.Touched:Connect(clone)
Edit:
local car = game.Workspace.car local debounce = false function clone(hit) local human = hit.Parent:FindFirstChild("Humanoid") -- This basically just checks if the the thing touching it is a player, and it won't get pressed by any other object if human then if not debounce then debounce = true local yes = car:Clone() yes.Parent = game.Workspace yes.Position = Vector3.new(300.905, 6.5, -275.073) wait(5) -- Set this to how long the debounce should be debounce = false end end end script.Parent.Touched:Connect(clone)
Hey you can add a cooldown by doing this:
local car = game.Workspace.car local cooldown = 3 -- put the cooldown in seconds here local onCooldown = false function clone() if not onCooldown then onCooldown = true local yes = car:Clone() yes.Parent = game.Workspace yes.Position = Vector3.new(300.905, 6.5, -275.073) wait(cooldown) onCooldown = false end end script.Parent.Touched:Connect(clone)
Haven't tested it but it should work
Alright, well I don't really know if this works, but combining your answers and some tutorials, I decided to go with the following. I don't know if this works...
local car = game.Workspace.car local cooldown = 3 -- put the cooldown in seconds here local onCooldown = false function clone(hit) if hit.Parent:FindFirstChild("Humanoid") then if not onCooldown then onCooldown = true local yes = car:Clone() yes.Parent = game.Workspace yes:MoveTo(Vector3.new(300.905, 6.5, -275.073)) wait(cooldown) onCooldown = false end end end script.Parent.Touched:Connect(clone)
If I went wrong, please tell me where