I want to make true false. I don’t want to simply use a break statement for my while loops. I don’t want to use a variable for my if statements. No, I want to set true to false if a condition is met. I would appreciate advice on how to achieve this.
Just use the not keyword? not true
That wont work for an already active while loop or an if statement using true
while true do
-- code
end
if true do
-- code
end
There is no way without a variable or using break.
I will find a way to do it. I’m not going to give up.
What’s your use case? Why can’t you just use break or use a variable?
Yes, what is your specific use case as in what code are you using that causes these issues? The bottom 2 errors are just caused by trying to check group stuff without the player being in the game. There are alternative ways to do this if you are expecting the player to not be in game.
Exactly. OP shouldn’t be asking for a way to make true false they should ask a question related to their specific issue.
I have a script checking if a player is in a group or if theyre in a table I use to access data using a while loop but sometimes when a player leaves the game it starts giving errors
So we can help you faster / better
Give the script ( function?) that have errors
How is making true false going to fix this issue? Can you go into more detail and provide code? Otherwise there isn’t much we can do.
local function addEmployee()
if profiles[string.lower(player.Name)] then
if #profiles[string.lower(player.Name)]["employeeIcons"] < 6000 then
coroutine.resume(coroutine.create(function()
local imageLabel = Instance.new("ImageLabel")
local uiCorner = Instance.new("UICorner")
local randomFriend = friendsUserIds[math.random(1, #friendsUserIds)]
local randomFriendImage
local ready
repeat
local success, error = pcall(function()
randomFriendImage, ready = players:GetUserThumbnailAsync(randomFriend, Enum.ThumbnailType.AvatarBust, Enum.ThumbnailSize.Size60x60)
end)
if not success then
task.wait(math.random(5, 50)/10)
end
until success
uiCorner.CornerRadius = UDim.new(0.2, 0)
uiCorner.Parent = imageLabel
imageLabel.BackgroundColor3 = Color3.fromRGB(95, 133, 117)
imageLabel.BorderSizePixel = 0
imageLabel.ScaleType = Enum.ScaleType.Stretch
imageLabel.ResampleMode = Enum.ResamplerMode.Default
imageLabel.Interactable = false
imageLabel.Active = false
if ready then
imageLabel.Image = randomFriendImage
imageLabel.Name = tostring(randomFriend)
else
imageLabel.Image = "rbxassetid://71208183538685"
imageLabel.Name = tostring(1)
end
if profiles[string.lower(player.Name)] then
if #profiles[string.lower(player.Name)]["employeeIcons"] < 6000 then
table.insert(profiles[string.lower(player.Name)]["employeeIcons"], imageLabel)
imageLabel.Parent = employeesListFrame
else
imageLabel:Destroy()
end
end
end))
end
end
end
if not inGroup then
if player then
local success, error = pcall(function()
inGroup = player:IsInGroup(35877032)
end)
if not success then
inGroup = false
warn(error)
end
end
end
the if statement and addEmployee function are both triggered by a while loop that starts when a player joins the server
players.PlayerRemoving:Connect(function(leavingPlayer)
if leavingPlayer == player then
if playerProfile then
if playerProfile:IsActive() then
playerProfile:EndSession()
end
end
profiles[string.lower(player.Name)] = nil
end
end)
I’m believe playerremoving fires before the player fully removes from the game which causes the error
Sorry if i am unable to write/copy your code I’m on phone.
Yeah i think the problem is that your PlayerRemoving:
event fires and even after the player is not in the game the loop continues to run and tries to do something with player
( that is equal to nil. As the error said)
Anyway you can fix this by stopping the loop when the player leaves
From the outside
- This is a bit harder but less code and the best in my opinion
Use a task.spawn( main function Loop ) to create a new thread from outside
local thread = task.spawn( main_function_Loop )
-- Code
PlayerRemoving:Connect(function()
-- Code
-- Code
task.cancel(thread)
end)
And when the player leaves call task.cancel(thread) to destroy/stop the loop from continuing
Someone has explained this with better English ( not the same problem but same solutions )
Or the inside
- Easy but a lot of copy pasting
Just check if the player exist in the start of every loop if not then stop the loop using break
If not player or player.Parent == nil then
break
end
please do not use any code provided for safety reasons