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

How can I make a script repeat itself? [closed]

Asked by
AspectW 431 Moderation Voter
7 years ago
Edited 7 years ago

How can I make

local SCP049=script.Parent;
local clone = SCP049:Clone()
SCP049.Humanoid.Died:connect(function()
wait(5)
SCP049:Destroy()
clone.Parent = Workspace
end)

repeat when its done without making roblox crash?

1
WOOOOO!!! QUESTION 40.000! RubenKan 3615 — 7y

Locked by youtubemasterWOW

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

2 answers

Log in to vote
2
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
7 years ago

When the initial Humanoid dies -that's it. The event never fires again. You have to attach a new function to the new humanoid.

However, you can't make infinitely complex code, so you can't use an anonymous function here:

local SCP049 = script.Parent;
local clone = SCP049:Clone()

function respawn()
    wait(5)
    SCP049:Destroy()
    SCP049 = clone:Clone()
    SCP049.Parent = workspace

    SCP049.Humanoid.Died:connect(respawn)
end

SCP049.Humanoid.Died:connect(respawn)
Ad
Log in to vote
-1
Answered by 7 years ago

Simple, use a

while true do 

end

Just put that script in there and put a wait somewhere in there like this

while true do 
wait(1)

end

so it doesn't keep repeating every like 0.1 of a second. It would lag out and crash your server!

If you have any questions feel free to ask : )