having trouble with subtracting leaderstats on client-server here is local script in the button
local plr = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
if plr.leaderstats.Coins.Value >= 100 then
game.ReplicatedStorage.Sphere2.Parent = plr.PlayerScripts
local coins = plr.leaderstats.Coins.Value
game.ReplicatedStorage.BuyRemotes.BoughtSphere2:FireServer(coins)
end
end)
EDIT: You are using a lot of bad practices… you don’t have a check on the server side (hackers) and you are passing the leaderstat value into the remote even though you have the player on the server side, I recommend changing your scripts to these instead:
Client:
local plr = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
if plr.leaderstats.Coins.Value >= 100 then
game.ReplicatedStorage.Sphere2.Parent = plr.PlayerScripts
game.ReplicatedStorage.BuyRemotes.BoughtSphere2:FireServer()
end
end)
Server:
game.ReplicatedStorage.BuyRemotes.BoughtSphere2.OnServerEvent:Connect(function(player)
local coins = player.leaderstats.Coins
if coins.Value >= 100 then
coins.Value = coins.Value - 100
end
end)