Script is Not Finding the Real Value of an IntValue

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)   

It might actually be 0 on the server, how are you changing/adding/giving coins to the player. If it’s through a local script or through the explorer (without clicking to change to current server) then your script still sees it as 0

The console in studio. I’ve also tried using the explorer/properties tab to change it.

What do you mean without clicking to change to current server?

Ok, so that’s most likely your problem, try while testing in studio, click the button that says CurrentClient (on the top bar) when you click it should say CurrentServer, then from there change the coins

1 Like