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

How to fix leaderstats script problem to account deaths in a Roblox game?

I am working for my game, I need help with the leaderstats to track my deaths. There are 2 data values, "Rip's" and "TotalRips" (DataStore), it is working, almost. Although it appears to be working, the problem is the first death doesn't count towards the TotalRips Count, after that it works. I put these 2 scripts in here:

local deathsStore = game:GetService("DataStoreService"):GetDataStore("TotalRips")
function playerAddedHandler(plr)  
	local playerKey = "Player_" .. plr.UserId 
	local leaderstats = Instance.new("Folder", plr)  
	leaderstats.Name = "leaderstats"
	local TotalRips = Instance.new("IntValue", leaderstats)
	TotalRips.Name = "TotalRips"
	TotalRips.Value = deathsStore:GetAsync(playerKey) 
	plr.CharacterAdded:Connect(function(char)
		char.Humanoid.Died:Connect(function()
			plr.leaderstats.TotalRips.Value = plr.leaderstats.TotalRips.Value + 1
			local success, err = pcall(function()
				deathsStore:SetAsync(playerKey, plr.leaderstats.TotalRips.Value)
			end)    
		end)
	end)
end
game.Players.PlayerAdded:Connect(playerAddedHandler)

Also here is another one of the script:

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats
	if player:FindFirstChild("leaderstats") then
		leaderstats = player.leaderstats
	else
		leaderstats = Instance.new("Folder")
		leaderstats.Name = "leaderstats"
		leaderstats.Parent = player
	end
	local Rip = Instance.new("IntValue")
	Rip.Name = "Rip's"
	Rip.Parent = leaderstats
	
	player.CharacterAdded:Connect(function(char)
		char.Humanoid.Died:Connect(function()
				
			Rip.Value = Rip.Value + 1
		
			
		end)
	end)
end)

I need help because it could be inaccurate for accounting these values.

1 answer

Hello, sorry for that but here is what is usually the problem:

  1. You made the variable wrong, here is what it should look like
TotalRips = "TotalRips"
  1. Other things related to TotalRips should also be the children and the parent should be the TotalRips

1 comment

0

I am sorry but it didn't work, when i paste the code it said: Error: (11,13) Syntax error: Expected identifier when parsing expression, got '['. The Rip's Count is working, put the TotalRips isn't.

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