It seems you are probably passing the player in the FireServer and the value after. Only send the value. The server automatically receives the player, so you don’t need to send it.
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr: Player, Amount: number) -- Type checking.
if not plr then return end -- If the player doesn't exist, stop the script.
pcall(function()
plr.leaderstats.Gems.Value -= Amount or 10
end)
end)
This essentially will catch all the errors that occur. Change the “10” value to whatever base value it should remove, in the instance that Amount does not exist, so the script won’t break.
Pcall will catch any errors and will make sure the script doesn’t break no matter what. Type checking will also (hopefully) help with errors, as well as checking if the player exists! Hopefully this helps you!
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(Player, Amount)
if Amount.Value then
Player.leaderstats.Gems.Value -= Amount.Value
elseif Amount ~= nil then
Player.leaderstats.Gems.Value -= Amount
end
end)