Leaderstats cash wont go down

i want to know what is going on with my code and why my leader stats cash wont go down when i rebirth but when i rebirth the cash does not go down in the leaderstats and stays the same. i have tried to slove this for a good 2 hours but cant figure out whats causing this outcome i’m not sure what script this has to do with though.

local open = false
local player = game.Players.LocalPlayer

script.Parent.RebirthButton.MouseButton1Click:Connect(function()
	if open == false then
		script.Parent.Frame.Visible = true
		script.Parent.RebirthButton.Text = "You need"..((player.leaderstats.Rebirths.Value+1)*2000).."to rebirth."
		open = true
	else
		script.Parent.Frame.Visible = false
		open = false
	end
end)

script.Parent.Frame.RebirthButton.MouseButton1Click:Connect(function()
	if player.leaderstats.Cash.Value >= ((player.leaderstats.Rebirths.Value+1)*2000) then
		game.ReplicatedStorage.RemoteEvents.Rebirth:FireServer()
		script.Parent.Frame.RebirthButton.Text = "Sucessfully Rebirthed"
		wait(2)
		script.Parent.Frame.Visible = false
		open = false
		script.Parent.Frame.RebirthButton.Text = "Rebirth"
	end
end)
1 Like

Put a print before and after checking the cash in that if statement and see if it goes through. If it does then it’s an issue with whatever server script handles this.
Where does that :FireServer() go to? Can you show us the server-side?

1 Like

this is the server script

local datastore = game:GetService("DataStoreService"):GetDataStore("players")

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Parent = player
	leaderstats.Name = "leaderstats"

	local cash = Instance.new("NumberValue")
	cash.Parent = leaderstats
	cash.Name = "Cash"

	local power = Instance.new("NumberValue")
	power.Parent = leaderstats
	power.Name = "Power"

	local rebirths = Instance.new("NumberValue")
	rebirths.Parent = leaderstats
	rebirths.Name = "Rebirths"

	local debounce = Instance.new("BoolValue")
	debounce.Value = false
	debounce.Name = "Debounce"
	debounce.Parent = player

	local key = "user-" .. player.userId

	local storeditems = datastore:GetAsync(key)

	if storeditems then
		cash.Value = storeditems[1] --Value of the cash, change "points" if you changed line 10
		rebirths.Value = storeditems[2]
		power.Value = storeditems[3]
	else
		local items = {cash.Value, rebirths.Value, power.Value}
		datastore:SetAsync(key, items)
	end
end)

game.Players.PlayerRemoving:connect(function(player)
	local items = {player.leaderstats.Cash.Value, player.leaderstats.Rebirths.Value, player.leaderstats.Power.Value}
	local key = "user-" .. player.userId

	datastore:SetAsync(key, items)
end)
1 Like

and this is the remote handler

local ReplicatedStorage = game.ReplicatedStorage

ReplicatedStorage.RemoteEvents.Power.OnServerEvent:Connect(function(player, valueFolder)
	if player.Debounce.Value == false then
		player.leaderstats.Power.Value = player.leaderstats.Power.Value + valueFolder.Power.Value*(player.leaderstats.Rebirths.Value + 1)
		player.Debounce.Value = true
		wait(valueFolder.Cooldown.Value)
		player.Debounce.Value = false
	end
end)
ReplicatedStorage.BindableEvents.Sell.Event:Connect(function(player)
	if player ~= nil then 
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + player.leaderstats.Power.Value*2
		player.leaderstats.Power.Value = 0 
	end
end)


ReplicatedStorage.RemoteEvents.Rebirth.OnServerEvent:Connect(function(player)
	if player.leaderstats then
		player.leaderstats.Cash.Value = 0
		player.leaderstats.Power.Value = 0
		player.Backpack:ClearAllChildren()
		player.leaderstats.Rebirths.Value = player.leaderstats.Rebirths.Value + 1
	end
end)
1 Like

This is your datastore, we’re asking to see the event bind for the rebirth remote event, it should look something like this:

Rebirth.OnServerEvent:Connect(function())

end)

or alternatively itll be a function binded like this:

function rebirthPlayer(player)
end

Rebirth.OnServerEvent:Connect(rebirthPlayer)

nevermind you just posted it, sorry lol

this is the one that fires the server

Try to perform some debugging on your end like adding print commands to see where exactly the script is failing/erroring/not working as intended.

there are no errors in the output

1 Like