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:

01local plr = game:GetService("Players").LocalPlayer
02 
03local function CheckIfEnough()
04 
05    if plr:WaitForChild("leaderstats").XP.Value >= 500 then
06        print("Test")
07        script.Parent.Parent.NextLevelBrick:Destroy()
08    end
09 
10end
11 
12plr: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.

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

Answer this question