Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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.

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`. TheeDeathCaster 2368 — 6y
0
What's the name of the gear you want to clone? Le_Teapots 913 — 6y

1 answer

Log in to vote
0
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
6 years ago

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
0
Thanks, but there is an problem... Gear is not cloning in your inventory, do you know whats the problem? AswormeDorijan111 531 — 6y
0
Have you checked the output for any errors? Rare_tendo 3000 — 6y
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 AswormeDorijan111 531 — 6y
0
I tried also playing place, turning it on but still nothing https://www.roblox.com/games/1590119563/Some-unknown-place AswormeDorijan111 531 — 6y
View all comments (4 more)
0
¨Ill try! AswormeDorijan111 531 — 6y
0
Sorry, i dont get it how to debug... AswormeDorijan111 531 — 6y
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. TheeDeathCaster 2368 — 6y
Ad

Answer this question