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

Why isn't the condition for my webhook script not working?

Asked by
iiSL_K 5
4 years ago

I am making a script that sends information to a discord server when a player has reached a certain amount of points. Everything is working but the condition.

game.Players.PlayerAdded:Connect(function(plr)
    local points = Instance.new("NumberValue",plr)
    points.Name = "Points"
    points.Value = 0

local url = "[My webhook]"
local http = game:GetService("HttpService")

if plr.Points >= 7.5 then
    local Data = {
    ['content'] = plr.Name.." Passed!"
    }

    Data = http:JSONEncode(Data)

    http:PostAsync(url, Data)
    end
end)

It keeps saying "attempt to compare number with userdata"

0
you gotta write plr.Points.Value in the if statement aipiox123 1 — 4y
0
also you can't use "[My webhook]" you gotaa use a real webhook lon233bcc 31 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

You referenced the points object and not it's value.

game.Players.PlayerAdded:Connect(function(plr)
    local points = Instance.new("NumberValue",plr)
    points.Name = "Points"
    points.Value = 0

local url = "[My webhook]"
local http = game:GetService("HttpService")

if plr.Points.Value >= 7.5 then -- now it references the value of points
    local Data = {
    ['content'] = plr.Name.." Passed!"
    }

    Data = http:JSONEncode(Data)

    http:PostAsync(url, Data)
    end
end)
Ad

Answer this question