Attempt to compare RBXScriptConnection error

Button.MouseButton1Click:Connect(function()
	if Player.leaderstats:WaitForChild("Player Coins").Value > Price then -- line 23/error here
		print("buy")
	else
		print("not enough money")
	end
end)

Error: PlayerGui.ShopGui.BuyButton.BuyScript:23: attempt to compare RBXScriptConnection < number
I’ve never encountered this error before and I’m not so sure what RBXScriptConnection is. If it helps, this is written in a server script inside the GUI

1 Like

The error means that Price is a RBXScriptConnections, which is basically just a connection to an event.
What is Price defined as?

price is a variable returned from a function above. (please note that i’ve never used returning so i’m trying to practice it here)

local Price = CycleValue:GetPropertyChangedSignal("Value"):Connect(function()
	if CycleValue.Value == 1 then
		Button.Text = "Buy Galaxy Chicken for: " .. ChickenTools["Galaxy Chicken"].Cost.Value
		return ChickenTools["Galaxy Chicken"].Cost.Value
	elseif CycleValue.Value == 2 then
		Button.Text = "Buy Radioactive Chicken for: " .. ChickenTools["Radioactive Chicken"].Cost.Value
		return ChickenTools["Radioactive Chicken"].Cost.Value
	elseif CycleValue.Value == 3 then
		Button.Text = "Buy Fire Chicken for: " .. ChickenTools["Fire Chicken"].Cost.Value
		return ChickenTools["Fire Chicken"].Cost.Value
	end
end)
1 Like

Price is not the variable returned from the function, it’s the connection to the event. I think this code should do what you want?:

local Price = 0
CycleValue:GetPropertyChangedSignal("Value"):Connect(function()
	if CycleValue.Value == 1 then
		Button.Text = "Buy Galaxy Chicken for: " .. ChickenTools["Galaxy Chicken"].Cost.Value
		Price = ChickenTools["Galaxy Chicken"].Cost.Value
	elseif CycleValue.Value == 2 then
		Button.Text = "Buy Radioactive Chicken for: " .. ChickenTools["Radioactive Chicken"].Cost.Value
		Price = ChickenTools["Radioactive Chicken"].Cost.Value
	elseif CycleValue.Value == 3 then
		Button.Text = "Buy Fire Chicken for: " .. ChickenTools["Fire Chicken"].Cost.Value
		Price = ChickenTools["Fire Chicken"].Cost.Value
	end
end)

Thank you for helping me out here, I was pretty confused on this one and this seems to work. I will look more into how to use returning properly :+1: