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

Repeat wait() until a value isn't nil. How can I do?

Hello, I'm facing a problem that i can't revolve by myself unfortunaly.

local player = game.Players.LocalPlayer

repeat wait() until not player.Stats:WaitForChild("R_KeyMoveset").Value == nil

while wait() do
	if player.Stats:WaitForChild("R_KeyMoveset").Value == nil then
		wait()
	else
		print(game.ReplicatedStorage.Movesets:FindFirstChild(player.Stats:WaitForChild("R_KeyMoveset").Value).Name.Value)
		local move = game.ReplicatedStorage.Movesets:FindFirstChild(player.Stats:WaitForChild("R_KeyMoveset").Value).Name.Value
		script.Parent.Text = script.Parent.Parent.Key.Value.." - "..move
	end
end

So first if i remove the line with the repeat the script will go to the second option (value isn't nil or "") and if i let it the script is still waiting. I need help to wait until the value isn't nil. Thanks for answers

1 comment

0

I believe you could do repeat wait() until player.Stats:WaitForChild("R_KeyMoveset").Value

1 answer

✓ Accepted answer

The not operator reversed the Boolean state of the given value. Therefore, if R_KeyMoveset becomes true, it flips to false. The logic is also stating that it’s asking to yield until R_KeyMoveset is actually nil, not the other way around. You can use the ~= not-equal-to operator to properly compare.

WaitForChild will also yield the code as well until it exists, so this also causes controversy with the logic of this line as well. Use FindFirstChild if you wish to continue apply a repeat wait.

repeat wait() until player.Stats:FindFirstChild("R_KeyMoveset") ~= nil

1 comment

0

Tysm!

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