Make a Bool/Number value reset after player dies

game.Players.PlayerAdded:Connect(function(player)
	local Charge = Instance.new("NumberValue")
	Charge.Name = "Charge"
	Charge.Value = 100
	Charge.Parent = player
	
	local Engine = Instance.new("BoolValue")
	Engine.Name = "Engine"
	Engine.Value = false
	Engine.Parent = player
end)

How can I make it so that the values are set to their original value when player respawns again?

1 Like
game.Players.CharacterAdded:Connect(function(player)
	if player:FindFirstChild("Charge") then
		player.Charge.Value = 100
	else
		local Charge = Instance.new("NumberValue")
		Charge.Name = "Charge"
		Charge.Value = 100
		Charge.Parent = player
	end
	if player:FindFirstChild("Engine") then
		player.Engine.Value = false
	else
		local Engine = Instance.new("BoolValue")
		Engine.Name = "Engine"
		Engine.Value = false
		Engine.Parent = player
	end
end)

replace your PlayerAdded script with this

With that script, the player wont get the value once they enter the server, it will only happens if they respawn

When you join CharacterAdded runs cause you get a character

Do a script with PlayerAdded and CharacterAdded into it and then print at every event, you will see that at first entrance on server only one print will show

I have a game that runs CharacterAdded in line 3 and it works when I join the game as well

CharacterAdded is not a valid member of Players “Players”

Well it doesn’t when i do that. Maybe there is a glitch. If it can work then my bad

oh my bad sorry CharacterAdded works when called directly on the player

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		if player:FindFirstChild("Charge") then
			player.Charge.Value = 100
		else
			local Charge = Instance.new("NumberValue")
			Charge.Name = "Charge"
			Charge.Value = 100
			Charge.Parent = player
		end
		if player:FindFirstChild("Engine") then
			player.Engine.Value = false
		else
			local Engine = Instance.new("BoolValue")
			Engine.Name = "Engine"
			Engine.Value = false
			Engine.Parent = player
		end
	end)
end)

try this

player isnt defined at the start

sorry I rushed it but I think I fixed it

was missing an end but i fixed it and it WORKS

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		if player:FindFirstChild("Charge") then
			player.Charge.Value = 100
		else
			local Charge = Instance.new("NumberValue")
			Charge.Name = "Charge"
			Charge.Value = 100
			Charge.Parent = player
		end
		if player:FindFirstChild("Engine") then
			player.Engine.Value = false
		else
			local Engine = Instance.new("BoolValue")
			Engine.Name = "Engine"
			Engine.Value = false
			Engine.Parent = player
		end
	end)
end)

ty bro

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.