Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why can't my script work everytime its triggered?

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago

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
0
Didn't work User#30241 0 — 4y
0
Could you give me the error it output then? XxTrueDemonxX 362 — 4y
Ad

Answer this question