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

Why is my achievement system not working for my npc?

Asked by 2 years ago

So i have a code here thats in an npc and i want to make it that like u can feed the npc and then when it gets to a certain amount it gives u the badge but the problem is that its not running for some reasing. the rest of the code runs fine its just the if food value == 6 part that dosnt work. i also tried putting several prints in it but also didint print. Also nothing was in the output. Can somebody help me?

full script:

local player = game.Players
local BadgeService = game:GetService("BadgeService")

local ServerStorage = game:GetService("ServerStorage")

local foodValue = script.Parent.FoodValue

script.Parent.Head.InteractProx.Triggered:Connect(function(plr)
    if plr.Character:FindFirstChild("Hamburger") then
        foodValue.Value = foodValue.Value + 1
        script.Parent.Head.InteractProx.Enabled = false
        plr.Character.Hamburger:Destroy()
    end
end)

if foodValue.Value == 6 then -- change to 6
    print("Food value is 7")
    local PlayerID = player.localPlayer.UserId
    local foodBadgeID = 2126781898

    local explosion = Instance.new("Explosion", script.Parent)

    explosion.Position = script.Parent.PrimaryPart.CFrame.Position

    BadgeService:AwardBadge(PlayerID, foodBadgeID)

elseif foodValue.Value == 5 then    
    print("Food value is 5")
    script.Parent.Head.Mesh:Destroy()
    script.Parent.Head.Shape = Enum.PartType.Ball

    script.Parent.Torso.Shape = Enum.PartType.Ball
    script.Parent.Torso.Size = Vector3.new(2.8, 2.8, 2.8)

elseif foodValue.Value == 4 then
    print("Food value is 4")
    script.Parent.Head.Mesh:Destroy()
    script.Parent.Head.Shape = Enum.PartType.Ball

    script.Parent.Torso.Shape = Enum.PartType.Ball
    script.Parent.Torso.Size = Vector3.new(2.8, 2.8, 2.8)
end

----------
wait(5)
local roomate = script.Parent
local humanoid = script.Parent.Humanoid

local pointA = game.Workspace.ApartmentHouse.GreenFlag

wait(5)
humanoid.Sit = false
humanoid:MoveTo(pointA.Position)


0
also sorry if its reupload i accidently deleat the old one Boyuanbogosess 17 — 2y

1 answer

Log in to vote
0
Answered by
Xientra 17
2 years ago

Correct me if I'm wrong, but it seems you're only checking the food value when the script first runs and not when the food value is updated.

I'd either move lines 16 - 42 in between lines 12 - 13:

script.Parent.Head.InteractProx.Triggered:Connect(function(plr)
    if plr.Character:FindFirstChild("Hamburger") then
        foodValue.Value = foodValue.Value + 1
        script.Parent.Head.InteractProx.Enabled = false
        plr.Character.Hamburger:Destroy()
        -- Lines 16 - 42
    end
end)

Or I'd use a GetPropertyChangedSignal:

foodValue:GetPropertyChangedSignal("Value"):Connect(function ()
    -- Lines 16 - 42
end)
0
oh thanks ill try that out Boyuanbogosess 17 — 2y
Ad

Answer this question