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

Attempt to comapare userdata with a number?

Asked by
lomo0987 250 Moderation Voter
10 years ago
PointsService = game:GetService("PointsService")
Stat = "KOs" 
game.Players.PlayerAdded:connect(function(p)
        repeat wait() until p:FindFirstChild("leaderstats") ~= nil
        repeat wait() until p.leaderstats:FindFirstChild(Stat) ~= nil
        repeat wait() until p:FindFirstChild("Need") ~= nil
        p.leaderstats[Stat].Changed:connect(function(prop)
                print("Value changed!")
                local need = p:FindFirstChild("Need")
                print("Found Need")
                if prop >= need then
                        game:GetService("PointsService"):AwardPoints(p.userId,1)
need = need + 5
print("Awarded points and need has went up")
                end
        end)
end)

Line 11, (if prop >= need then) is bugged. I don't know why it won't find the value of it.

1 answer

Log in to vote
0
Answered by
Destrings 406 Moderation Voter
10 years ago

That because it is userdata. You are defining need as

local need = p:FindFirstChild("Need")

And you can't compare it to a number, I think you wanted to defined it as follow

local need = p:FindFirstChild("Need").Value
0
I need to specify the Value? :/ Lol. If I did really mess up that much i'm going to cry. ): lomo0987 250 — 10y
0
I'm guessing Need is a NumberValue, you got a reference to the Instance, which is userdata. You need to access its property Value to actually get the stored value. Destrings 406 — 10y
0
Yeah, I know. But when I was coding it, I looked at 'prop' and if you look, it doesn't get the value like that, so I imagined for some odd reason that it was 100% fine. lomo0987 250 — 10y
0
Also, it still doesn't work. It provides a player point when they get a kill. :/ lomo0987 250 — 10y
0
At least is not an error anymore Destrings 406 — 10y
Ad

Answer this question