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

Why can't my script work everytime its triggered?

I recently made a script that spawns a part from ServerStorage to workspace and it only works once before it breaks and doesn't work after I try it again. Why doesn't my script work EVERYTIME when it is triggered

function Ontouched(PartTest)
    wait(3)
    game.ServerStorage.Laser.Parent = game.Workspace
    wait(14)
    workspace.Laser:Destroy()
end

1 answer

You're moving the laser to the workspace and destroying it which removes it for good. You should utilize cloning for stuff line this.

function OnTouched(partTest)
	wait(3)
	local laserCopy = game:GetService("ServerStorage").Laser:Clone() --Clones the laser and stores it in a variable for later so you don't accidentally delete the wrong laser
	laserCopy.Parent = workspace
	wait(14)
	laserCopy:Destroy() --Destroy the copy of the laser specifically stored in this variable so it will only ever destroy that specific clone
end

2 comments

0

Didn't work

0

Could you give me the error it output then?

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