I have a script which assigns a local attribute 'playing' to every player which first enters the game.
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(modelPlayer)
local playing = Instance.new("BoolValue")
playing.Name = "playing"
playing.Parent = player
end)
end)
This works fine and the player will have a playing bool in the explorer through Players. I also have another script which changes the bool to true from false when they press a GUI button which successfully changes it in the explorer. (This is not the issue, the bool is definitely updated in the explorer I have checked)
The problem arises when I have a server script which checks if the player has their 'playing' bool value set to true in order for them to be teleported out of the lobby however even if their bool has been updated successfully when the function is called it does not teleport them and the console still outputs that their value is 'false'
function MovePlayers(...)
local spawns = {...}
for _, plr in pairs(game:GetService("Players"):GetPlayers()) do -- iterate through table of players
local playing = plr.playing.Value --Check if the player's playing bool means they can be teleported
print(playing)
if plr.Character and playing == true then -- if character exists and has playing set to true then
plr.Character.Torso.CFrame = CFrame.new(spawns[math.random(#spawns)]) -- move their torso to a random spawn
end
end
end
If however I set the players playing bool value to 'true' at the very start, this function does detect that their value is true and will teleport them. I am quite confused as to why it will work if the value is initially assigned to true but not if it was initially false and then changed to true later on. I would appreciate any help, thanks!

2 comments
Thanks worked, appreciate the explanation and the detailed code response. It's always these little things I'm not aware about in lua that get me, is there anywhere I can learn stuff like that? I had no idea a local script wouldn't update it but I guess it makes sense.
You're absolutely welcome! Thank you or feedback.