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

Badge not being awarded from server?

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

3 comments

0

Because it's in ROBLOX studio. test in a actual game

0

oh wow I'm stupid

0

Write solved in front of the question or delete it.

1 answer

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

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