There isn't any errors when I run the game but this doesn't print when I put my XP value to 100:
game.Players.PlayerAdded:Connect(function(plr)
local Xp = plr.XP
if Xp.Value == 100 then
print("Hey I have 100 xp ")
end
end)
There isn't any errors when I run the game but this doesn't print when I put my XP value to 100:
game.Players.PlayerAdded:Connect(function(plr)
local Xp = plr.XP
if Xp.Value == 100 then
print("Hey I have 100 xp ")
end
end)
Your issue here is that you're checking if the value of the player's XP is equal to 100 as soon as they join the game, not once you actually change it to 100.
We can fix this by using .Changed on the value.
Essentially .Changed is just an event that fires once a value is changed.
Note: This would be used in a LocalScript located somewhere inside the player, such as StarterGui.
local plr = game.Players.LocalPlayer
local Xp = plr:WaitForChild("XP") -- Using WaitForChild() so the script won't break if "XP" has not loaded yet.
Xp.Changed:Connect(function()
if Xp.Value == 100 then
print("Hey I have 100 XP!")
end
end)
If you have any comments or queries, then just leave a comment here!
Learn more about the .Changed event here.
Happy scripting!
This discussion is preserved as it was. New answers, comments, and votes are closed.