This script is in ServerScriptService and it does not seem to detect changes to the player’s coins. Look in the comments of the script for more info.
local remoteevent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
remoteevent.OnServerEvent:Connect(function(plr, tool, price)
print("received")
if game:GetService("ServerStorage")[tool] then
print("tool exists")
print(plr)
print(plr.leaderstats.Coins.Value) -- problem.. the coins value keeps getting printed as 0, even though its not
if plr.leaderstats.Coins.Value >= price then -- and therefore this function does not work
print("player has enough")
plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value - price
game:GetService("ServerStorage")[tool]:Clone().Parent = game:GetService("Players")[plr].Backpack
print("given")
end
end
end)