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

What is wrong with this?

Asked by 10 years ago

Hello, I am trying to make a boolvalue, so that when a player dies it turns off. Can you fix this script that I made?

h = script.Parent:FindFirstChild("Humanoid")
if h then
    player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
    if player then
        x = player:WaitForChild("Ingame") 

        h.Died:connect(function()
            x.Value = false
        end)
    end
end

1 answer

Log in to vote
0
Answered by 10 years ago

Some of the methods/lines in this script aren't even necessary. I'll put a [X] next to the ones that aren't...

h = script.Parent:FindFirstChild("Humanoid")
if h then --[X]
    player = game.Players:GetPlayerFromCharacter(script.Parent.Parent) --[X]
    if player then --[X]
        x = player:WaitForChild("Ingame") 

        h.Died:connect(function()
            x.Value = false
        end)
    end --[X]
end --[X]


This code is pretty inefficient as is, and the code I have written below will run a bit faster, and actually produce the desired result.

Humanoid = script.Parent:WaitForChild("Humanoid")
InGame = script.Parent:WaitForChild("Ingame")

Humanoid.Died:connect(function ()
    InGame.Value = false
end)
Ad

Answer this question