Point System failing

Hello everyone, Im currently coding a Point system, I made a part leading with a script inside of it to make the system work, Heres the code:


local PointGiver = script.Parent
local pointstoAdd = 10


local function onTouched(hit)
	local player =
		game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		
		player.leaderstats.Points.Value =
			player.leaderstats.Points.Value + pointstoAdd
		print(player.Name .. "earned" .. "Points!")
	end
end

PointGiver.Touched:Connect(onTouched()) 

However I made the leaderstats aswell:


local leaderboard = script.Parent

local function updateLeaderboard()
	local players =
		game.Players:GetPlayers()
	for i, player in ipairs(players) 
	do
		local points = 
			player.Leaderstats.Points.Value
		leaderboard["Player" .. 
			i].Text = player.Name .. ": " .. points
		end
	end




game.Players.PlayerAdded:Connect(updateLeaderboard)
for _, player in
	ipairs(game.Players:GetPlayers()) do
	
	player.leaderstats.Points:GetpropertyChangedSignal("Value"):Connect(updateLeaderboard())
end 

local function onPlayerAdded(player)
	
	local leaderstats =
		Instance.new ("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	
	local points =
		Instance.new("IntValue")
	points.Name = "Points"
	points.Value = 0
	
	points.Parent = leaderstats
end




game.Players.PlayerAdded:Connect(onPlayerAdded)

I don’t get any errors, But when I go to touch the part nothing happens.

PointGiver.Touched:Connect(onTouched())
You’re calling the onTouched function wrong.
It should be:
PointGiver.Touched:Connect(onTouched)

This same error happens again.
player.leaderstats.Points:GetpropertyChangedSignal("Value"):Connect(updateLeaderboard())
has the exact same issue.
Change this to:
player.leaderstats.Points:GetPropertyChangedSignal("Value"):Connect(updateLeaderboard)

Off the top of my head I see no other blaring errors. Fixing these should fix your code.

Because my last attempt was deleted for a community guideline violation for apparently asking for a place file, I will explain in depth.

Can you send a RBXL file of the code that is not working? The code you provided does not in any way help solve your problem. If you want to fix the issue, provide the community with resources. A place file will allow us as developers to debug your code and develop an optimal solution to the problem. I say this because there may be other code in your place that may be interfering with the functionality of your code. Not to mention, the code blocks you provided are not blocked correctly so it is hard for us as a community to give you assistance with this problem.

Thanks,

1 Like