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

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

Asked by 8 years ago

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

Log in to vote
0
Answered by 8 years ago

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


0
Server side isn't working, saying line 10 has an error. "Attempt to index local 'badge' (a number value)" Pawsability 65 — 8y
0
I don't know what's wrong, I didn't index 'badge' xxracerdudexx 75 — 8y
Ad

Answer this question