✓ Accepted answer
##Problem
Your while loop is not exiting. While the loop is running nothing outside of it will be run until the loop terminates. A while loop can terminate when the condition becomes false (since you're using while true do it will never terminate), or if you use the keyword break.
##Solution
For your intended purposes, you're not wanting to exit the while loop, so we will want to move the while loop. The while loop will need to go after lines 14 and 15 in your code in order to add the stats to the leaderboard.
##Additional Information
I have added the comparing of team colors to the script. How the script now works is if the player is ever on the team with a TeamColor of Bright blue, then the player will be awarded five points. Since TeamColors are BrickColor values, you will need to compare the TeamColor with a BrickColor. That is why the script has newPlayer.TeamColor == BrickColor.new('Bright blue').
##Final Script
function onPlayerEntered(newPlayer)
local stats = Instance.new("IntValue")
stats.Name = "leaderstats"
local points = Instance.new("IntValue")
points.Name = "Currency"
points.Value = 0
stats.Parent = newPlayer
points.Parent = stats
while true do
if newPlayer.TeamColor == BrickColor.new('Bright blue') then
wait(5)
points.Value = points.Value + 50
end
end
end
game.Players.PlayerAdded:connect(onPlayerEntered)
######Hopefully this answered your question, if so do not forget to hit the accept answer button. If you have another other questions, feel free to comment below.
3 comments
Yep, @M39a9am3R did it way better
So basically you want to continually change the parent the parent of the leaderstats/int values
Thanks @JohnTUnderwood for catching my problem. That was a mistake :D