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

Brick won't delete itself when the player has enough XP, any ideas?

Asked by 3 years ago

I have a game where you advance to the next level by earning XP and when you have the designated amount of XP a part will be destroyed so you can go through it (Client sided).

I believe that it should work but I get no printed text etc. No error either.

LOCAL SCRIPT:

local plr = game:GetService("Players").LocalPlayer

local function CheckIfEnough()

    if plr:WaitForChild("leaderstats").XP.Value >= 500 then
        print("Test")
        script.Parent.Parent.NextLevelBrick:Destroy()
    end

end

plr:WaitForChild("leaderstats").XP.Value.Changed:Connect(CheckIfEnough() -- If the xp value of a player changes it will run the function.

1 answer

Log in to vote
2
Answered by 3 years ago
Edited 3 years ago

Listen to the changed event of the value instance, not the number itself. Also, do .Changed:Connect(CheckIfEnough) because :Connect expects a function, but by including (), you are calling the function.

plr:WaitForChild("leaderstats").XP.Changed:Connect(CheckIfEnough)
0
Thank you! johnoscarbhv1 137 — 3y
Ad

Answer this question