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

Why does my if statement proceed to run no matter what?

In the game I am currently working on, the lobby disappears and the map exists. When this happens, a value is supposed to change to true so it doesn't continue to go and just break. For some reason, the if statement says the bool is false even if it isn't. This only started happening after I added the 2nd script (the one at the bottom of the page). If anyone knows what's going on, please help me out and leave an answer. Thanks.

local RS = game.ReplicatedStorage
local Workspace = game.Workspace
local ss = game.ServerStorage
local value = Workspace.Trueorno.Value

while true do
	wait(1)
	print("still going")
	if game.Players.NumPlayers >= 1 then
		if value == false then
			wait(9)
			game.Workspace.Trueorno.Value = true
			wait(1)
			for i,Player in pairs(game.Players:GetPlayers()) do
				local Dagger = RS.DaggerWood:Clone()
				Dagger.Parent = Player.Backpack
			end
			RS.Map1.Parent = Workspace
			Workspace.Lobby.Parent = RS
		end
	end
	print("no")
end
while true do
	wait(3)
	if game.Workspace.Trueorno == true then
		print("1true")
		if game.Players.NumPlayers == 1 then
			print("2true")
			game.Workspace.Trueorno = false
			game.Workspace.Map1.Parent = game.ReplicatedStorage
			game.ReplicatedStorage.Lobby.Parent = game.Workspace
		end
	end
end

1 comment

0

And by the way, the value does change. The script just doesnt think it did.

1 answer

✓ Accepted answer

Hello,

Your code is not updating the value of value, you should put it inside the loop.

local RS = game.ReplicatedStorage
local Workspace = game.Workspace
local ss = game.ServerStorage
--Removed value from here

while true do
    wait(1)
    local value = Workspace.Trueorno.Value -- Inserted value here
    print("still going")
    if game.Players.NumPlayers >= 1 then
        if value == false then
            wait(9)
            game.Workspace.Trueorno.Value = true
            wait(1)
            for i,Player in pairs(game.Players:GetPlayers()) do
                local Dagger = RS.DaggerWood:Clone()
                Dagger.Parent = Player.Backpack
            end
            RS.Map1.Parent = Workspace
            Workspace.Lobby.Parent = RS
        end
    end
    print("no")
end

1 comment

0

Thank you!

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