1 not adding onto a value

hello, i have a script to show before i need any help, firstly is this piece of code in serverscriptservice.

AttackModeActivated.Event:Connect(function(character)
		local player = Players:GetPlayerFromCharacter(character)
		allPlayers[table.find(allPlayers, player)].AttackModeActivations.Value += 1
		AMLChanged:FireAllClients(allPlayers)
end)

A bindable event fires once the player touches the brick and its meant to update a custom leaderstats GUI but it doesnt as this piece of code doesnt work when the player touches the part. I know it doesnt add the value as I checked and it stays at 0, any help?

the script inside a part to fire the bindable event

local Stage2 = script.Parent
local AttackModeActivated  = game.ServerStorage.AttackModeActivated

Stage2.Touched:Connect(function(otherPart)
		local model = otherPart:FindFirstAncestorOfClass("Model")
		if(model and model:FindFirstChildWhichIsA("Humanoid")) then
				AttackModeActivated:Fire(model)
		end
end)

Can i get more code? What is allPlayers?

Try to add this after line 2 of the snippet you provided and reply with what it printed in console:

print(allPlayers[table.find(allPlayers, player)].AttackModeActivations.Value)

This code basically makes a new template on the custom leaderboard and put all of the information in:

local Players = game:GetService("Players")
local AMLChanged = game.ReplicatedStorage.Events.AMLChanged
local AttackModeActivated  = game.ServerStorage.AttackModeActivated

local allPlayers = {}

Players.PlayerAdded:Connect(function(player)
		local AttackModeActivations = Instance.new("IntValue")
		AttackModeActivations.Name = "AttackModeActivations"
		AttackModeActivations.Value = 0
		AttackModeActivations.Parent = player

		local Username = Instance.new("StringValue")
		Username.Name = "Username"
		Username.Value = player.Name
		Username.Parent = player

		local Thumbnail = Instance.new("StringValue")
		Thumbnail.Name = "Thumbnail"
		local ThumbType = Enum.ThumbnailType.HeadShot
		local ThumbSize = Enum.ThumbnailSize.Size420x420
		local content, isReady = Players:GetUserThumbnailAsync(player.UserId, ThumbType, ThumbSize)
		Thumbnail.Value = content
		Thumbnail.Parent = player

		table.insert(allPlayers, player)
		AMLChanged:FireAllClients(allPlayers)
end)

Players.PlayerRemoving:Connect(function(player)
	table.remove(allPlayers, table.find(allPlayers, player))
	AMLChanged:FireAllClients(allPlayers)
end)

AttackModeActivated.Event:Connect(function(character)
		local player = Players:GetPlayerFromCharacter(character)
		allPlayers[table.find(allPlayers, player)].AttackModeActivations.Value += 1
		AMLChanged:FireAllClients(allPlayers)
end)

as well as this one which is inside of the custom leaderstats gui:
which updates every time the leaderstats changed event is fired

local StatsFrame = script.Parent.Stats
local PlayerScores = StatsFrame.PlayerStats

local LeaderboardPlayerTemplate = game.ReplicatedStorage.PlayerScore
local AMLChanged = game.ReplicatedStorage.Events.AMLChanged

local playerScoresFrame = {}

local function UpdateStatsUI(_players)
		if (#playerScoresFrame < #_players) then
				for i = #playerScoresFrame + 1, #_players, 1 do
						local StatsTemplate = LeaderboardPlayerTemplate:Clone()
						StatsTemplate.Parent = PlayerScores
						playerScoresFrame[i] = StatsTemplate
				end
		end
		if (#playerScoresFrame > #_players) then
			for i = #_players + 1, #playerScoresFrame, 1 do
					playerScoresFrame[i]:Destroy()
					playerScoresFrame[i] = nil
			end
	 end
	for i,v in ipairs(_players) do
			playerScoresFrame[i].PlayerName.Text = _players[i].Username.Value
			playerScoresFrame[i].PlayerScore.Text = _players[i].AttackModeActivations.Value
			playerScoresFrame[i].PlayerPhoto.Image = _players[i].Thumbnail.Value
	end
end

AMLChanged.OnClientEvent:Connect(UpdateStatsUI)

Off that code is kindof messy. Does it generate any errors? Also why do you store all the players in a dict?

I dont really like this part:

allPlayers[table.find(allPlayers, player)].AttackModeActivations.Value += 1

Cant you just do this?:

player.AttackModeActivations.Value += 1

ServerScriptService.AttackModeLeaderboard:37: attempt to index nil with ‘AttackModeActivations’, it showed me this.

I knew it! Try to replace the code with my code in my previous response so the function will look like this:

AttackModeActivated.Event:Connect(function(character)
		local player = Players:GetPlayerFromCharacter(character)
		
		player.AttackModeActivations.Value += 1

		AMLChanged:FireAllClients(allPlayers)
end)

still shows the exact error and doesn’t add value

Can you send the full error so i can see wich lines does it?

The error links to this line:
AMLChanged:FireAllClients(allPlayers)
at the end of the function

Thats wierd. Can you launch the game and send me everything under the player. Basically what i think is happening is that the value AttackModeActivation doesnt exist in the player. It is wierd that its referencing line 38 wich fires a event.

How is character passed in bindable event?
Does AttackModeActivations exist on player and server?


it shows the same on server

Its unlikly but just to be sure. Add wait(5) at the begining of the servescriptservice code to ensure that the value exists

It just changed from line 38 to 37 where it tries to add the 1 onto the value, and it gives the same error:

ServerScriptService.AttackModeLeaderboard:37: attempt to index nil with 'AttackModeActivations’

Ok its time for some debuging here is the code with a lot of print statements to check if some important values are nil:

local Players = game:GetService("Players")
local AMLChanged = game.ReplicatedStorage.Events.AMLChanged
local AttackModeActivated  = game.ServerStorage.AttackModeActivated

local allPlayers = {}

Players.PlayerAdded:Connect(function(player)
		local AttackModeActivations = Instance.new("IntValue")
		AttackModeActivations.Name = "AttackModeActivations"
		AttackModeActivations.Value = 0
		AttackModeActivations.Parent = player

		local Username = Instance.new("StringValue")
		Username.Name = "Username"
		Username.Value = player.Name
		Username.Parent = player

		local Thumbnail = Instance.new("StringValue")
		Thumbnail.Name = "Thumbnail"
		local ThumbType = Enum.ThumbnailType.HeadShot
		local ThumbSize = Enum.ThumbnailSize.Size420x420
		local content, isReady = Players:GetUserThumbnailAsync(player.UserId, ThumbType, ThumbSize)
		Thumbnail.Value = content
		Thumbnail.Parent = player

		table.insert(allPlayers, player)
		print(allPlayers)
		AMLChanged:FireAllClients(allPlayers)
end)

Players.PlayerRemoving:Connect(function(player)
	table.remove(allPlayers, table.find(allPlayers, player))
	print(allPlayers)
	AMLChanged:FireAllClients(allPlayers)
end)

AttackModeActivated.Event:Connect(function(character)
		print(character)
		print(character:GetDescendants())
		local player = Players:GetPlayerFromCharacter(character)
		print(player)
		print(player.Name)
		pcall(function()
			print(player.AttackModeActivations)
		end)
		allPlayers[table.find(allPlayers, player)].AttackModeActivations.Value += 1
		AMLChanged:FireAllClients(allPlayers)
end)

It seems like it gave a error when it tried to print the players name.

I edited my previos response try that