My points not save on leaderboard

Hi everyone, i just made a leaderboard that save players points, it works, but the problem is when player click to earn points it doesn’t save on the leaderboard.

the local script that give you points, it is inside of StarterCharacterScripts:

Starts here:

local UIS = game:GetService(“UserInputService”)

local picked_up_sandwich = false

local sandwich = nil

UIS.InputBegan:Connect(function(input)

local ray = workspace.Camera:ViewportPointToRay(UIS:GetMouseLocation().X, UIS:GetMouseLocation().Y)

if input.UserInputType == Enum.UserInputType.MouseButton1 and not picked_up_sandwich then
	for i,v in pairs(workspace:GetDescendants()) do
		if v.ClassName == "UnionOperation" and (ray.Origin + ray.Direction * (ray.Origin - v.Position).Magnitude - v.Position).Magnitude <= 1 or  v.ClassName == "UnionOperation" and v.Name ~= "Baseplate" and (ray.Origin + ray.Direction * (ray.Origin - v.Position).Magnitude - v.Position).Magnitude <= 1 then
			picked_up_sandwich = true
			sandwich = v
			local connection = nil
			connection = game:GetService("RunService").RenderStepped:Connect(function()
				if not picked_up_sandwich then connection:Disconnect() return end
				local ray = workspace.Camera:ViewportPointToRay(UIS:GetMouseLocation().X, UIS:GetMouseLocation().Y)
				sandwich.Position = ray.Origin + ray.Direction * 15
				sandwich.Orientation = Vector3.new(0,0,0)
				sandwich.CanCollide = false
			end)
		end
	end

elseif input.UserInputType == Enum.UserInputType.MouseButton1 and picked_up_sandwich then
	for i,v in pairs(workspace:GetDescendants()) do
		if v.ClassName == "Attachment" and v.Name == sandwich.Name and (ray.Origin + ray.Direction * (ray.Origin - v.WorldPosition).Magnitude - v.WorldPosition).Magnitude <= 1 then
			local new_sandwich = sandwich
			game:GetService("RunService").RenderStepped:Connect(function()
				new_sandwich.Position = v.WorldPosition
				new_sandwich.Orientation = Vector3.new(0,0,0)
				new_sandwich.CanCollide = false
			end)
		end
	end

	picked_up_sandwich = false
	local player = game.Players.LocalPlayer
	player.leaderstats.Level.Value = player.leaderstats.Level.Value + 1

	local RogerEating = game.Workspace.RogerEating
	local eatingSound = game.Workspace.Sounds.Eating
	RogerEating.Position = Vector3.new(112.64, 4.91, 55.799)
	eatingSound:Play()
	wait(0.09)
	RogerEating.Position = Vector3.new(137.266, 4.91, 55.799)
	wait(0.009)
	RogerEating.Position = Vector3.new(112.64, 4.91, 55.799)
	eatingSound:Play()
	wait(0.09)
	RogerEating.Position = Vector3.new(137.266, 4.91, 55.799)
	sandwich.CanCollide = true
	sandwich:Destroy()
	sandwich = nil
	local food = game.Workspace.Cool
	local clonedFood = food:Clone()
	clonedFood.Parent = game.Workspace
	clonedFood.Position = Vector3.new(107.914, 3.236, 55.777)
end

end)

first image is leaderstats:
Captura de Pantalla 2022-09-10 a la(s) 14.22.18

second image is leaderboard:
Captura de Pantalla 2022-09-10 a la(s) 14.22.34

1 Like

Have you tried use a Remote Event?

I see that you’ve used game.Players.LocalPlayer variable, That means you are using it client-sided.

local RemoteEvent = game.ReplicatedStorage.Test

RemoteEvent.OnServerEvent:Connect(function(Player, Giving)
        --[ Player.Stats.Currency.Value += Giving
end)

-- [ Client

RemoteEvent:FireServer(DesiredNumber)
1 Like

Thank you for reply, alright, let me try it

1 Like

It doesn’t seem to work, it appears the same amount on the leaderboard, doesn’t increase on it

Can you please show the changes on your script? If you dont mind, I can might help you change it a bit.

1 Like

I totally forgot about the leaderboard, I think you might have to implement a Update function for it.

Example

while wait(YourDesiredTime) do
      -- [ Make the templates create again with the current Stat of the Player.
end
1 Like

Sure, here is the code, it is inside of the ServerScriptService

local remote = game.ReplicatedStorage.Action

remote.OnServerEvent:Connect(function(player,giving)

player.leaderstats.Level.Value += giving

end)

remote:FireServer(1)

Sorry, the FireServer function, only works in the client. Here a little change for the LocalScript.

local ray = workspace.Camera:ViewportPointToRay(UIS:GetMouseLocation().X, UIS:GetMouseLocation().Y)

if input.UserInputType == Enum.UserInputType.MouseButton1 and not picked_up_sandwich then
	for i,v in pairs(workspace:GetDescendants()) do
		if v.ClassName == "UnionOperation" and (ray.Origin + ray.Direction * (ray.Origin - v.Position).Magnitude - v.Position).Magnitude <= 1 or  v.ClassName == "UnionOperation" and v.Name ~= "Baseplate" and (ray.Origin + ray.Direction * (ray.Origin - v.Position).Magnitude - v.Position).Magnitude <= 1 then
			picked_up_sandwich = true
			sandwich = v
			local connection = nil
			connection = game:GetService("RunService").RenderStepped:Connect(function()
				if not picked_up_sandwich then connection:Disconnect() return end
				local ray = workspace.Camera:ViewportPointToRay(UIS:GetMouseLocation().X, UIS:GetMouseLocation().Y)
				sandwich.Position = ray.Origin + ray.Direction * 15
				sandwich.Orientation = Vector3.new(0,0,0)
				sandwich.CanCollide = false
			end)
		end
	end

elseif input.UserInputType == Enum.UserInputType.MouseButton1 and picked_up_sandwich then
	for i,v in pairs(workspace:GetDescendants()) do
		if v.ClassName == "Attachment" and v.Name == sandwich.Name and (ray.Origin + ray.Direction * (ray.Origin - v.WorldPosition).Magnitude - v.WorldPosition).Magnitude <= 1 then
			local new_sandwich = sandwich
			game:GetService("RunService").RenderStepped:Connect(function()
				new_sandwich.Position = v.WorldPosition
				new_sandwich.Orientation = Vector3.new(0,0,0)
				new_sandwich.CanCollide = false
			end)
		end
	end

	picked_up_sandwich = false
	local  event = game.ReplicatedStorage.Action
    event:FireServer(1)

	local RogerEating = game.Workspace.RogerEating
	local eatingSound = game.Workspace.Sounds.Eating
	RogerEating.Position = Vector3.new(112.64, 4.91, 55.799)
	eatingSound:Play()
	wait(0.09)
	RogerEating.Position = Vector3.new(137.266, 4.91, 55.799)
	wait(0.009)
	RogerEating.Position = Vector3.new(112.64, 4.91, 55.799)
	eatingSound:Play()
	wait(0.09)
	RogerEating.Position = Vector3.new(137.266, 4.91, 55.799)
	sandwich.CanCollide = true
	sandwich:Destroy()
	sandwich = nil
	local food = game.Workspace.Cool
	local clonedFood = food:Clone()
	clonedFood.Parent = game.Workspace
	clonedFood.Position = Vector3.new(107.914, 3.236, 55.777)
end

Server Script →

local remote = game.ReplicatedStorage.Action

remote.OnServerEvent:Connect(function(player,giving)

player.leaderstats.Level.Value += giving

end)

-- [ Just remove the fire event function.

Please reply me if It did a effect.

1 Like

Thank you so much!, it works!, thank you for your time!

No problem! If you ever have a problem with the FireServer() function. Just check over here its functionalitys!

1 Like

okay, thank you so much!, I will take a look up