Leaderstats not working

ActionReciever(Script)

local debounce = false
game.ReplicatedStorage.Action.OnServerEvent:Connect(function(player,action)
	if action == "Click" then
		if debounce == true then
		else
			debounce = true
			player.leaderstats.Points.Value = player.leaderstats.Points.Value + 1*(player.leaderstats.Rebirths.Value + 1)
			wait(0.2)
			debounce = false
			
		end
		
	end
end)

leaderstats & Data Saving(Script)

local DataStoreService = game:GetService("DataStoreService")
local pointsStore = DataStoreService:GetDataStore("Points")
local rebirthsStore = DataStoreService:GetDataStore("Rebirths")
game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder",player)
	leaderstats.Name = "leaderstats"
	
	local points = Instance.new("IntValue",leaderstats)
	points.Name = "Points"
	points.Value = pointsStore:GetAsync(player.UserId) or 0
	
	local rebirths = Instance.new("IntValue",leaderstats)
	rebirths.Name = "Rebirths"
	rebirths.Value = rebirthsStore:GetAsync(player.UserId) or 0
	
end)
game.Players.PlayerRemoving:Connect(function(player)
	pointsStore:SetAsync(player.UserId,player.leaderstats.Points.Value)
	rebirthsStore:SetAsync(player.UserId,player.leaderstats.Rebirths.Value)
end)

ClickSender(Local Script)

local mouse = game.Players.LocalPlayer:GetMouse()

mouse.Button1Down:Connect(function(player)
	game.ReplicatedStorage.Action:FireServer("Click")
end)

LocalScript(Local Script)

local player = game.Players.LocalPlayer
player.PlayerGui.Stats.Points.TextLabel.Text = player.leaderstats:WaitForChild("Points").Value
player.PlayerGui.Stats.Rebirths.TextLabel.Text = player.leaderstats:WaitForChild("Rebirths").Value

player.leaderstats.Points:GetPropertyChangedSignal("Value"):Connect(function()
	player.PlayerGui.Stats.Points.TextLabel.Text = player.leaderstats:WaitForChild("Points").Value
end)
player.leaderstats.Rebirths:GetPropertyChangedSignal("Value"):Connect(function()
	player.PlayerGui.Stats.Rebirths.TextLabel.Text = player.leaderstats:WaitForChild("Rebirths").Value
end)

Rebirth(LocalScript)

local player = game.Players.LocalPlayer
script.Parent.Frame1.TextButton.Activated:Connect(function()
	if script.Parent.Frame.Visible == true then
		script.Parent.Frame.Visible = false
	else
		script.Parent.Frame.Visible = true
	end
end)
script.Parent.Frame.ExitButton.Activated:Connect(function()
	script.Parent.Frame.Visible = false
end)
script.Parent.Frame.RebirthButton.Activated:Connect(function()
	if player.leaderstats.Points.Value < (player.leaderstats.Rebirths.Value + 1) * 2500 then
	else
		player.leaderstats.Points.Value = 0
		player.leaderstats.Rebirths.Value = player.leaderstats.Rebirths.Value + 1
	end
end)
player.PlayerGui.Rebirths.Frame.RebirthButton.Text = "Rebirth for "..(player.leaderstats.Rebirths.Value + 1) * 2500 .." Coins"
player.leaderstats.Rebirths:GetPropertyChangedSignal("Value"):Connect(function()
	player.PlayerGui.Rebirths.Frame.RebirthButton.Text = "Rebirth for "..(player.leaderstats.Rebirths.Value + 1) * 2500 .." Coins"
end)

When the player rebirths, the points are reset to 0, but once the player clicks again, their Points go to 2501 instead of 1

Because the player rebirth now is 1

yeah, but im saying their points are supposed to go to 0, then they click and gain 2 per click. After they rebirth the value is 0(what i wanted) then it goes to 2501 after they click for the first time instead of 2.

1 Like

You’re incrementing the value from a LocalScript. Only the client will see that value change. The server does not acknowledge this change, so it still sees the points as 2501. Therefore, when it needs to increment the points value, it sees 2500 and then adds 1 to that, so 2501.

You need to have the server handle rebirths.

2 Likes

Oh, so make a remote event right?

1 Like

Never trust the client, always work on the server.

1 Like