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

Badge not being awarded from server?

Asked by 6 years ago

I've made a badge that players get if they've been in the game for over an hour. Problem is, the script for it doesn't work. It keeps warning me with this message: "Sorry, badges can only be awarded by Roblox game servers." so I double checked, and the script was indeed a server script running inside the game. It was under ServerScriptService, which I don't think should have affected anything. The script is here:

local players = game:GetService("Players")
local repStorage = game:GetService("ReplicatedStorage")
local timeEvent = repStorage:WaitForChild("getPlayerTime")
local folder = script.ClientTimes

players.PlayerAdded:Connect(function(plr)
    local val = Instance.new("NumberValue")
    val.Name = plr.Name.."Time"
    val.Value = 0
    val.Parent = folder
    local newThread = coroutine.wrap(function()
        while val do
            wait()--.98)
            val.Value = val.Value + 10 --usually it waits .98 seconds and adds 1 second, but I wasn't going to wait an hour to test a badge
            print(val.Value/60/60)
            if val.Value/60/60 > 1 then
                game:GetService("BadgeService"):AwardBadge(plr.UserId, 1640722449)
            end
        end
    end)
    newThread()
end)

players.PlayerRemoving:Connect(function(plr)
    local oldval = folder:FindFirstChild(plr.Name.."Time")
    if oldval then
        oldval:Destroy()
    end
end)

timeEvent.OnServerInvoke = function(player)
    timeVal = folder:FindFirstChild(tostring(player).."Time")
    if timeVal then
        if timeVal:IsA("NumberValue") then
            return timeVal.Value
        else return 0
        end
    else return 0
    end
end
0
Because it's in ROBLOX studio. test in a actual game User#19524 175 — 6y
0
oh wow I'm stupid steven73598233 75 — 6y
0
Write solved in front of the question or delete it. Axceed_Xlr 380 — 6y

1 answer

Log in to vote
0
Answered by
Lualaxy 78
6 years ago

Make sure to test things like that ingame not in roblox studio. Badges can not be awarded in roblox studio. Only ingame.

Ad

Answer this question