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

Why does this break after the player dies?

Asked by 8 years ago

So I made a noclip script, but for some reason it breaks as soon as the player dies (which it shouldn't) Script is in a LocalScript in the playergui, with ResetPlayerGuiOnSpawn set to false.

Run, PlrChar, PlrHum, and NoClip are declared.

Anybody know the problem i'm at a complete loss.

Run.RenderStepped:connect(function()
    local Find = PlrChar:FindFirstChild("Humanoid")
    if (Find) then
        PlrHum = Find
    end
    if (NoClip) then
        PlrHum:ChangeState(Enum.HumanoidStateType.StrafingNoPhysics)
    end
end)
0
Try reseting PlrChar, PlrHum, and NoClip when you respawn. SynphonyKnight 85 — 8y
0
Put your second if statement inside of your first one. GoldenPhysics 474 — 8y
0
Nothing still, tried putting the second if statement in the first one. DangCoolIsReal 32 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

I'd say it's because PlrChar doesn't get updated, but there is no way I could know that.

local PlrChar, PlrHum
local NoClip = true
local Run = game:GetService( "RunService" )
local player = game.Players.LocalPlayer

player.CharacterAdded:connect(function(char) 
    PlrChar = char
end)

while true do
    local Find = PlrChar:FindFirstChild("Humanoid")
    if (Find) then
        PlrHum = Find

    if (NoClip) then
            PlrHum:ChangeState(Enum.HumanoidStateType.StrafingNoPhysics)
    end
    end
    Run.RenderStepped:wait() -- RenderStepped used with connect is bad idea, since connect spawns new Lua threads every time it's fired. You could also try using BindToRenderStep.
end

This should work, but again, I'm not sure what other part of your script is already doing.

0
Thank you! That fixed it! DangCoolIsReal 32 — 8y
Ad

Answer this question