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

Is there anyway you can use AwardBadge and UserHasBadge in a LocalScript?

I have this script that I made, that is a LocalScript in the player's backpack, but I didn't realize that you can't use them as LocalScripts, and I'm not really sure on how I can fix this.. Any possible way without major change?

wait(0.1)
local Player = game:GetService("Players").LocalPlayer
local Timer = Player:WaitForChild("Time")
local Badge = game:GetService("BadgeService")

if not (Badge:UserHasBadge(Player.userId, 0)) then -- did have a badgeid, just removed it
	if (Timer) then
		while wait(60) do
			Timer.Value = Timer.Value + 1
			if (Timer.Value == 1440) then
				Badge:AwardBadge(Player.userId, 0) -- did have a badgeid, just removed it
				wait(0.1)
				Timer.Value = 0
			end
		end
	end
end

1 answer

Maybe using RemoteFunctions. In server sided script in ServerScriptStorage:

local HasBadge = Instance.new("RemoteFunction",game.ReplicatedStorage)
HasBadge.Name = "HasBadge"

local AwardBadge = Instance.new("RemoteFunction",game.ReplicatedStorage)
AwardBadge.Name = "AwardBadge"

local Badge = game:GetService("BadgeService")

HasBadge.OnServerInvoke = function(player, badge)
	return Badge:UserHasBadge(player.UserId,badge)
end

AwardBadge.OnServerInvoke = function(player,badge)
	Badge:AwardBadge(player.UserId,badge)
end

In Your Localscript:

wait(0.1)
local Player = game:GetService("Players").LocalPlayer
local Timer = Player:WaitForChild("Time")
local HasBadge = game.ReplicatedStorage:WaitForChild("HasBadge")
local AwardBadge = game.ReplicatedStorage:WaitForChild("AwardBadge")

--My Notes: InvokeServer inputs player argument for you
if not (HasBadge:InvokeServer(0)) then -- did have a badgeid, just removed it
    if (Timer) then
        while wait(60) do
            Timer.Value = Timer.Value + 1
            if (Timer.Value == 1440) then
		--My Notes: InvokeServer inputs player argument for you
                AwardBadge:InvokeServer(0) -- did have a badgeid, just removed 
                wait(0.1)
                Timer.Value = 0
            end
        end
    end
end


2 comments

0

Server side isn't working, saying line 10 has an error. "Attempt to index local 'badge' (a number value)"

0

I don't know what's wrong, I didn't index 'badge'

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