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

why does line 9 of this leaderboard script throw an error???

game.Players.PlayerAdded:connect(function(plr) 
 local stats = Instance.new("IntValue", game.Workspace)		
 stats.Name = "leaderstats"	
 local points = Instance.new("IntValue", stats)
 points.Name = "Points"
 points.Value = 0
 plr.CharacterAdded:connect(function(char)
	(char:WaitForChild("Humanoid")).Died:connect(function()
		plr.leaderstats.points.Value = plr.leaderstats.points.Value - 1
	end)
end)
end)

why does line 9 of this leaderboard script throw an error once humanoid dies???

2 answers

✓ Accepted answer
game.Players.PlayerAdded:connect(function(plr) 
	local stats = Instance.new("IntValue", plr)     
	stats.Name = "leaderstats" 
	local points = Instance.new("IntValue", stats)
	points.Name = "Points"
	points.Value = 0
	plr.CharacterAdded:connect(function(char)
		(char:WaitForChild("Humanoid")).Died:connect(function()
			points.Value = points.Value - 1
		end)
	end)
end)

2 comments

0

why does this wpork

0

because I change the parent of the stats.

Look back up at line 5, where you name the points(in the leaderstats model) as "Points". When referencing this, you have to use that name. In line 9, you look under player using plr, which is fine because that is a variable, then leaderstats, which is fine because the name is "leaderstats", but then you look for an object called "points", when the childs you are really looking for is "Points".

Long story short, capitalize points when you use it because the name you set it as is capitalized as well, so the script should be

plr.leaderstats.Points.Value = plr.leaderstats.Points.Value - 1

1 comment

0

Still doesnt work...

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