Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why are my int values not increasing on player death?

When the players die the values are not being updated. I have tried running this in player starter scripts, playergui, and have even cloned it directly into the player. It is not working.

Any help is appreciated.

First attempt using local script.

local player = game.Players.LocalPlayer
local char = player.Character
repeat wait() until char

char:FindFirstChild("Humanoid").Died:connect(function()
	if player.TeamColor == "Bright red" then
		game:GetService("Workspace").LeaderBoard.Red.Value = game:GetService("Workspace").LeaderBoard.Red.Value + 1
	elseif player.TeamColor == "Bright blue" then
		game:GetService("Workspace").LeaderBoard.Blue.Value = game:GetService("Workspace").LeaderBoard.Blue.Value + 1
	end
end)

Second attempt using remote events.

Local script:

local player = game.Players.LocalPlayer
local char = player.Character
repeat wait() until char

char:FindFirstChild("Humanoid").Died:connect(function()
	game.ReplicatedStorage.Died:FireServer()
end)

Server script:

function died (player)
	print(player.TeamColor)
	if player.TeamColor == "Bright red" then
		workspace.LeaderBoard.Red.Value = workspace.LeaderBoard.Red.Value + 1
		print("Red Died")
	elseif player.TeamColor == "Bright blue" then
		workspace.LeaderBoard.Blue.Value = workspace.LeaderBoard.Blue.Value + 1
		print("Blue Died")
	else print("Error Error Error")
	end
end

game.ReplicatedStorage.Died.OnServerEvent:connect(died)

I am able to print TeamColor but not check the value. All attempts are printing the Error.

I have tried checking it by TeamColor.Name, and TeamColor.Color. Same results.

3 comments

0

I do not believe you can change leaderboard values with a LocalScript in a FilteringEnabled environment. Though personally I have not gone and tested this.

0

I was testing this script, and the weird thing is that the 'Died' event is not firing at all.

0

Filtering enabled is not on. I have been trying to figure this out all day. I changed the script to use remote events. The Died event is now firing but it is still not updating the values. I will post the new scripts.

3 answers

✓ Accepted answer

player.TeamColor must be a BrickColor, not a string. Therefore, instead of comparing player.TeamColor with a string, compare it with an actual BrickColor (e.g.player.TeamColor == BrickColor.new("Bright red") instead of player.TeamColor == "Bright red".

This discussion is preserved as it was. New answers, comments, and votes are closed.