Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

1 comment

0

Thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.