Leaderstats not working

Script:

function check()
	local parts = workspace:GetPartsInPart(Goal, prams)

	if table.find(parts, Ball) then -- Check if the instance 'Ball' is inside the array of parts
		Ball.Anchored = true

		game.Workspace.RedPoint:FireAllClients(Ball)

		workspace.Ball.Position = Vector3.new(10, 110.5, -3)
		workspace.Ball.Position = Vector3.new(-25.5, 3.799, 1)

		resetRed(); resetBlue()

		game.Workspace.RedPoints.Value = game.Workspace.RedPoints.Value + 1

		Ball.Anchored = false
		Ball.AssemblyLinearVelocity = Vector3.new(0, 0, 0)
		Ball.AssemblyAngularVelocity = Vector3.new(0, 0, 0)
		print(workspace.Ball.Value.Value.Name)
		local scorer = workspace.Ball.Value.Value.Name
		local scorerplayer = game.Players[scorer]
		
		local goals = scorerplayer:FindFirstChild("leaderstats"):WaitForChild("Goals").Value
		
		goals += 1
	end    
end

while task.wait(0.05) do
	check()
end

The leaderstats are not updating.

Error messages: None

This is the error:

local goals = scorerplayer:FindFirstChild("leaderstats"):WaitForChild("Goals").Value
goals += 1

This is because your variable is simply reading the value.
Do this instead:

local goals = scorerplayer:FindFirstChild("leaderstats"):WaitForChild("Goals")
goals.Value += 1
2 Likes

Why would that make a difference?

3 Likes

I will try it though, idk if it works

3 Likes

It works, why did it make a difference?

3 Likes

Because variables do not change properties, it simply reads the value and gives you that when the variable is requested.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.