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

Why is my loop breaking even tho a Value is not true?

Hello. I have a problem. I am trying to make a loop start only when the player press "New game", but it's not working. The loop starts before the player press new game. What is wrong?

while true do
if game.ReplicatedStorage.GameStarted.Value == true then
	break
end	

wait(5)
hederlunden = game.Lighting.Hederlunden1
hederlunden2 = game.Lighting.Hederlunden2
hederlunden3 = game.Lighting.Hederlunden3
hederlunden4 = game.Lighting.Hederlunden4
while true do
hederlunden.Parent = game.Workspace
wait(5)
hederlunden.Parent = game.Lighting
hederlunden2.Parent = game.Workspace
wait(5)
hederlunden2.Parent = game.Lighting
hederlunden3.Parent = game.Workspace
wait(5)
hederlunden3.Parent = game.Lighting
if game.ReplicatedStorage.IsOn.Value == false then
hederlunden4.Parent = game.Workspace
wait(5)
end
end
end

3 comments

0

is the gameStarted bool changed when the player presses new game?

0

Yes.

0

script.Parent.Enabled = true script.Parent.BackGround.NewGame.MouseButton1Click:Connect(function() script.Parent.Enabled = false game.ReplicatedStorage.GameStarted.Value = true end)

1 answer

✓ Accepted answer

script:

script.Parent.Button.MouseButton1Click:Connect(function() --  change this to your button path
game.ReplicatedStorage.GameStarted.Value = true
wait(5)
hederlunden = game.Lighting.Hederlunden1
hederlunden2 = game.Lighting.Hederlunden2
hederlunden3 = game.Lighting.Hederlunden3
hederlunden4 = game.Lighting.Hederlunden4
while true do
hederlunden.Parent = game.Workspace
wait(5)
hederlunden.Parent = game.Lighting
hederlunden2.Parent = game.Workspace
wait(5)
hederlunden2.Parent = game.Lighting
hederlunden3.Parent = game.Workspace
wait(5)
hederlunden3.Parent = game.Lighting
if game.ReplicatedStorage.IsOn.Value == false then
hederlunden4.Parent = game.Workspace
wait(5)
end
end
end





end) 

3 comments

0

I'm sorry but... where should I put the script? I tried putting it into the gui but it didn't work.

0

Oh wait! I'm sorry, I put it in the wrong button...

0

remember to change the button path to script.Parent

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