The code that is below is inside a script that is inside a part. All of it works, but I am still confused about why it is spawning 2 items and the button cannot be pressed multiple times to spawn more than once.
local myBrick = script.Parent
local function imTriggered(part)
local humanoid = part.Parent:FindFirstChild("Humanoid")
if humanoid then
print ("Human")
local Sound = game.Workspace.Sound
Sound:Destroy()
local Segway = game.ServerStorage.SegwayKit
local Segway2 = Segway:Clone()
Segway2.Name= "Segway2"
Segway2.Parent= workspace
end
end
myBrick.Touched:Connect(imTriggered)
Alright I changed it to this and it’s still having the same two problems:
local buttonPressed = false
local myBrick = script.Parent
if not buttonPressed then
buttonPressed=true
function imTriggered(part)
local humanoid = part.Parent:FindFirstChild("Humanoid")
if humanoid then
print ("Human")
local Sound = game.Workspace.Sound
Sound:Destroy()
local Segway = game.ServerStorage.SegwayKit
local Segway2 = Segway:Clone()
Segway2.Name= "Segway2"
Segway2.Parent= workspace
buttonPressed = false
end
end
end
myBrick.Touched:Connect(imTriggered)
Yeah it is the same thing. The debounce thing will work, it just needs to be inside the imtriggered() function, right next to where you check if humanoid.
local buttonPressed = false
local myBrick = script.Parent
if not buttonPressed then
buttonPressed=true
function imTriggered(part)
local humanoid = part.Parent:FindFirstChild("Humanoid")
if humanoid then
print ("Human")
-- local Sound = game.Workspace.Sound
-- Sound:Destroy()
local Segway = game.ServerStorage.SegwayKit
local Segway2 = Segway:Clone()
Segway2.Name= "Segway2"
Segway2.Parent= workspace
buttonPressed = false
end
end
end
myBrick.Touched:Connect(imTriggered)
I don’t know if you misunderstood, but I meant putting script:Destroy() once the script is done doing what it needs to do. I didn’t mean delete the script, just destroying it in the game to stop it from running more than once.
Although I’m surprised the DeBounce isn’t working.
Alright the item is still being spammed with this script what’s wrong? It seems like I did everything right?
local buttonPressed = false
local myBrick = script.Parent
if not buttonPressed then
function imTriggered(part)
buttonPressed=true
local humanoid = part.Parent:FindFirstChild("Humanoid")
if humanoid then
print ("Human")
-- local Sound = game.Workspace.Sound
-- Sound:Destroy()
local Segway = game.ServerStorage.SegwayKit
local Segway2 = Segway:Clone()
Segway2.Name= "Segway2"
Segway2.Parent= workspace
wait(5)
buttonPressed = false
end
end
end
myBrick.Touched:Connect(imTriggered)