I try looping this script fails to, can anyone help?
local Detector = script.Parent local TimesClicked = 0 local target = game.ReplicatedStorage.ClickDetector script.Parent.mouseClick:Connect(function(Player) Detector:Destroy() wait(5) local ClickDetector = target:Clone() ClickDetector.Parent = game.Workspace.Rock TimesClicked = TimesClicked +0.5 if TimesClicked >= 3 and TimesClicked ~= nil then Player.leaderstats.LifeFormFound.Value = Player.leaderstats.LifeFormFound.Value +1 script.Parent.Parent.Transparency = 1 script.Parent.Parent.CanCollide = false wait(20) script.Parent.Parent.Transparency = 0 script.Parent.Parent.CanCollide = true end end)
Someone help please!
On line 1, you set Detector equal to the parent of the script.
On line 4, you created an event witch will run when the Detector is used.
Line 5 is the first thing the script does when the Detector is used, this deletes the detector thus deleting the script (due to the fact the script is a child of the Detector), this will end script execution instantly.
Here is the solution:
local Detector = script.Parent local TimesClicked = 0 local target = game.ReplicatedStorage.ClickDetector script.Parent.mouseClick:Connect(function(Player) local ClickDetector = target:Clone() ClickDetector.Parent = game.Workspace.Rock TimesClicked = TimesClicked +0.5 if TimesClicked >= 3 and TimesClicked ~= nil then Player.leaderstats.LifeFormFound.Value = Player.leaderstats.LifeFormFound.Value +1 script.Parent.Parent.Transparency = 1 script.Parent.Parent.CanCollide = false wait(20) script.Parent.Parent.Transparency = 0 script.Parent.Parent.CanCollide = true Detector:Destroy() end end)
Moving the Destroy()
to the end of the script means that it happens last, this will give the script a chance to finish execution.
If this helped you, make sure to accept the answer, it will help us both out.
I see your problem. The script
you're running is parented to Detector
. When you call
Detector:Destroy()
in Line 05, it destroys the script, therefore stopping execution.