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

When dead reset scripts in Workspace?

Hello everybody,

I'd like to know if it's possible to reset my scripts write in the Workspace when the Character dies. For example, i change the color and material of a button when i click on it but after the Character dies, it's still changed. My goal is to reset the button to the original one. I tried to search on forum and Web but can't find anything about it.

I'd like to know if it exists a way to reset my scripts (one-by-one? or all at the same time?) Also, the game has many spawns (like a obby).

Thank you in advance for your help.

1 answer

✓ Accepted answer

If you want to reset workspace scripts use this:

  • use a Server Script

  • place it in Starter Character Scripts

  • clone all scripts into lighting

  • put this code into the server script




script.Parent.Humanoid.Died:Connect(function() --// checks for players death
for i,v in pairs(workspace:GetDescendants()) do 
  if v:IsA("Script") then
     v:Destroy()
   end
end
for i,v in pairs(game.Lighting:GetDescendants()) do -- // gets the descendants and checks for scripts
  if v:IsA("Script") then
        v:Clone().Parent = workspace --// fixed thanks to ImKidra
      end
   end
end)

4 comments

0

idk but maybe v:Clone().Parent? so it happens everytime he resets i think

0

My bad i rushed it yea.

0

Thank you.

0

Badly, i probably made mistake (i'm new on learning LUA): i create Script in Starter Character Scripts (can't find Server Script) and copy/paste scripts from Workspace but the reset doesn't work on it.

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