#Where should i put this badge giver in the chezburger to make it work?

1 messages · Page 1 of 1 (latest)

carmine ruin
#

Hello, i am trying to make it so that when you use the chezburger item it gives you badge. The problem is I don't know where to put the code that gives you the badge or if it even works/is possible. Heres the script i have for it right now (btw i am a noob at scripting)
` ``lua
local Tool = script.Parent;
local BadgeService = game:GetService("BadgeService")
local BadgeId = 1581764212673767
enabled = true

function onActivated()
if not enabled then
return
end

enabled = false
Tool.GripForward = Vector3.new(-.981, .196, 0)
Tool.GripPos = Vector3.new(-.5, -0.6, -1.5)
Tool.GripRight = Vector3.new(0, -0, -1)
Tool.GripUp = Vector3.new(0.196, .981, 0)


Tool.Handle.DrinkSound:Play()

wait(.8)
 local h = Tool.Parent:FindFirstChild("Humanoid")
if (h ~= nil) then
    if (h.MaxHealth > h.Health + 1.6) then
        h.Health = h.Health + 1.6
    else    
        h.Health = h.MaxHealth
    end
end

Tool.GripForward = Vector3.new(-1, 0, 0)
Tool.GripPos = Vector3.new(-.5, -.1, 0)
Tool.GripRight = Vector3.new(0, 0, 1)
Tool.GripUp = Vector3.new(0,1,0)

enabled = true
local Player = game.Players[onActivated.Parent.Name]
BadgeService:AwardBadge(Player.UserId, BadgeId)

end

function onEquipped()
Tool.Handle.OpenSound:play()
end

script.Parent.Activated:connect(onActivated)
script.Parent.Equipped:connect(onEquipped)
` ``

silver otterBOT
#

studio** You are now Level 1! **studio

rose meadow
# carmine ruin Hello, i am trying to make it so that when you use the chezburger item it gives ...

Put the badge giver code inside the onActivated function

local Tool = script.Parent
local BadgeService = game:GetService("BadgeService")
local BadgeId = 1581764212673767
local enabled = true

function onActivated()
    if not enabled then
        return
    end

    enabled = false
    Tool.GripForward = Vector3.new(-.981, .196, 0)
    Tool.GripPos = Vector3.new(-.5, -0.6, -1.5)
    Tool.GripRight = Vector3.new(0, 0, -1)
    Tool.GripUp = Vector3.new(0.196, .981, 0)

    Tool.Handle.DrinkSound:Play()

    wait(0.8)
    
    local character = Tool.Parent
    local humanoid = character:FindFirstChild("Humanoid")
    
    if humanoid then
        if humanoid.MaxHealth > humanoid.Health + 1.6 then
            humanoid.Health = humanoid.Health + 1.6
        else    
            humanoid.Health = humanoid.MaxHealth
        end
    end

    Tool.GripForward = Vector3.new(-1, 0, 0)
    Tool.GripPos = Vector3.new(-.5, -.1, 0)
    Tool.GripRight = Vector3.new(0, 0, 1)
    Tool.GripUp = Vector3.new(0, 1, 0)

    enabled = true

    -- Get the player from the character :/
    local player = game.Players:GetPlayerFromCharacter(character)

    if player then
        --ccheck if the player already has the badge
        if not BadgeService:HasBadge(player.UserId, BadgeId) then
            BadgeService:AwardBadge(player.UserId, BadgeId)
        else
            print(player.Name .. " already has the badge.")
        end
    end
end

function onEquipped()
    Tool.Handle.OpenSound:Play()
end

script.Parent.Activated:Connect(onActivated)
script.Parent.Equipped:Connect(onEquipped)
#

Also local Player = game.Players[onActivated.Parent.Name] will no work coz onActivated.Parent refers to the parent of the tool, which is the character of the player, not the actual player but just the character in the workspace

carmine ruin
#

Oh ok got it, thanks for the tip on parents!