Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

**if points > Cost then...** returning "user ... attempt to compare number with userdata"?

I created a button with a local script in it Link: http://i.imgur.com/ogML7pR.png.

Here is the code:

-- 				BUY SYSTEM, CREATED BY ASWORMEDORIJAN111, FOR TEST.
-- 							7.4.2018.  OR    4/7/2018										




-- VARIABLES


Enabled = script.Parent.Enabled
Cost = script.Parent.SwordCost.Value
ItemName = script.Parent.SwordName.Value
local player = game.Players.LocalPlayer
local character = player.Character
local backpack = player.Backpack
local points = player.leaderstats


-- CODING SECTION


if (Enabled == true) then -- This is code for 'Enabled' value.
	script.Disabled = false
else
	script.Disabled = true
end

local itemf = game.Lighting
local item = itemf:FindFirstChild(ItemName)

function onclick()
	if points > Cost then 
		item:Clone().Parent = backpack
		points = points - Cost
	end
end

script.Parent.MouseButton1Click:connect(onclick)



And the output is here: http://i.imgur.com/DsnG4PE.png.******** Idk where did I failed... Sorry for my bad English.

2 comments

1

points is the leaderstats; if it's a number value, you'd do points.Value, otherwise you'd do it for a money object in it points.Money.Value.

0

What's the name of the gear you want to clone?

1 answer

At line 32, you're attempting to compare a number with an object, which will of course, return an error stating : 'attempt to compare a number with a userdata(object or something else)'

Here's how you can resolve this problem:

if points.Value > Cost then

8 comments

0

Thanks, but there is an problem... Gear is not cloning in your inventory, do you know whats the problem?

0

Have you checked the output for any errors?

0

Yep, I checked output and nothing. But everything is correct. I tried outing it in normal script, and local script too but still nothing, i tried

0

I tried also playing place, turning it on but still nothing https://www.roblox.com/games/1590119563/Some-unknown-place

0

¨Ill try!

0

Sorry, i dont get it how to debug...

0

In a nushell: Put a bunch of prints where you might think the codes not working, then see whichones print and which ones don't.

This discussion is preserved as it was. New answers, comments, and votes are closed.