Attempt to compare Instance to number

So I was making a shop system to improve on one I made a while ago that dont work anymore and I keep getting the error in the title. FYI the event passes through the player, the amount of the item and the item from the client

Here is code
the error is on if leaderstats.Coins.Value >= amount then

local RS = game:GetService("ReplicatedStorage")
local event = RS:WaitForChild("Purchase")

event.OnServerEvent:Connect(function(player, amount, item)
	local leaderstats = player.leaderstats
	local coins = leaderstats.Coins
	if leaderstats.Coins.Value >= amount then
		coins.Value -= amount
		print("Succesful Purchase")
		local item = RS:FindFirstChild(item)
		local clone = item:Clone()
		clone.Name = item.Name
		clone.Parent = player.Backpack

Make sure amount is given as a number value.

No the instance is the leaderstats.Coins.Value the amount is an int variable

well can we see the :FireServer() line, that could be the issue

1 Like

Here ya go:

local button = script.Parent
local players = game.Players
local player = players.LocalPlayer

local amount = 100
local RS = game:GetService("ReplicatedStorage")
local event = RS:WaitForChild("Purchase")
local item = "Sword"

	event:FireServer(player, amount, item)

yep that’s the problem all right

change this to

event:FireServer(amount, item)
1 Like

Question how would I get the player that fired the event?

The player is passed by roblox automatically (always the first parameter)

you already have the player in the OnServerEvent given from the client

you don’t need it in the FireServer

so player would be event.OnServerEvent.player? Sorry I don’t know much about remote events

no all I want you to change is that one line, everything should work after that

@D0RYU means this line.

event.OnServerEvent:Connect(function(player, amount, item)

You don’t need to fire the local player since the first parameter bolded above will always have the player that fired the event. It’s given to you automatically. So keep that line as it is.

1 Like