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
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)