Hello! So I have a script that starts after you hit a hitbox. (Any player) But its also continuing very fast and the other script cant delete the hitbox in time.
MainScript - Script
game.Workspace:WaitForChild("HitBox").Touched:Connect(function()
game.Workspace:WaitForChild("HitBox"):Destroy()
game.Workspace.Sounds["power outage sound effect"]:Play()
game.Workspace.Sounds.phone:Stop()
game.Workspace.Sounds["FNAF: PhoneGuy Night 1"]:Play()
game.Lighting.FogEnd = 40
end)
Script that deletes hitbox
game.ReplicatedStorage.StartingSoon.OnServerEvent:Connect(function()
local HitBox = script.HitBox
HitBox.Parent = game.Workspace
end)
game.ReplicatedStorage.NightStart.OnServerEvent:Connect(function(Players)
game.Workspace.Lights:Destroy()
end)
error am getting like 5 times.
Lights is not a valid member of Workspace
Try using just one script with the following contents:
local Debounce = false
game.Workspace:WaitForChild("HitBox").Touched:Connect(function()
if Debounce == false then
Debounce = true
game.Workspace:WaitForChild("HitBox"):Destroy()
game.Workspace.Sounds["power outage sound effect"]:Play()
game.Workspace.Sounds.phone:Stop()
game.Workspace.Sounds["FNAF: PhoneGuy Night 1"]:Play()
game.Lighting.FogEnd = 40
end
end)
I have added a debounce, which will prevent the code from happening multiple times.
If you want to reactivate it, implement a way to change Debounce to false again.
still gives the error:
Lights is not a valid member of Workspace
and then the power goes out quick because the remote event was fired too much