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

(intermediate) Script Half-way works, but nothing happens at the end. No out put errors?

Asked by 5 years ago
01local h = script.Parent.Humanoid
02 
03while true do
04    h:MoveTo(workspace.DontClean1.Position)
05    wait(5)
06    h:MoveTo(workspace.DontClean2.Position)
07    wait(5)
08end
09 
10if h.Health then
11    if h.Health == 0 then
12        game.Lighting.SuperEvilKeycard:Clone().Parent = game.Players.LocalPlayer.Backpack
13        script.Parent:Destroy()
14    end
15end

The humanoid moves, but when it dies, nothing happens. There isn't any output errors, i dont know what's happening. as always, i would be happy to elaborate

0
You could try using the Humanoid.Died event instead virushunter9 943 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

As the post above me said, you've got a loop that won't let your script continue. Therefore, you're going to need to force the script to run two things at once. Scary, I know. This is when we can use the Spawn() function, which you can read more about here.

01local h = script.Parent.Humanoid
02 
03function onDeath()
04    if h.Health then
05        if h.Health == 0 then
06        game.Lighting.SuperEvilKeycard:Clone().Parent = game.Players.LocalPlayer.Backpack
07        script.Parent:Destroy()
08        end
09    end
10end
11 
12spawn(function(onDeath))
13 
14while true do
15    h:MoveTo(workspace.DontClean1.Position)
16    wait(5)
17    h:MoveTo(workspace.DontClean2.Position)
18    wait(5)
19end

If this helped you out, consider accepting this answer. If not, let me know and I'll be sure to help you out further.

0
None of it works ScriptsALot 91 — 5y
Ad

Answer this question