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 4 years ago
local h = script.Parent.Humanoid

while true do
    h:MoveTo(workspace.DontClean1.Position)
    wait(5)
    h:MoveTo(workspace.DontClean2.Position)
    wait(5)
end

if h.Health then
    if h.Health == 0 then
        game.Lighting.SuperEvilKeycard:Clone().Parent = game.Players.LocalPlayer.Backpack
        script.Parent:Destroy()
    end
end

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 — 4y

1 answer

Log in to vote
0
Answered by 4 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.

local h = script.Parent.Humanoid

function onDeath()
    if h.Health then
        if h.Health == 0 then
        game.Lighting.SuperEvilKeycard:Clone().Parent = game.Players.LocalPlayer.Backpack
        script.Parent:Destroy()
        end
    end
end

spawn(function(onDeath))

while true do
    h:MoveTo(workspace.DontClean1.Position)
    wait(5)
    h:MoveTo(workspace.DontClean2.Position)
    wait(5)
end

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 — 4y
Ad

Answer this question