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

if statements are stopping my function?

I want to make a random map selector, but it seems that the selector is picking a map and not continuing, I want it to pick a map and then keep repeating

local function changed()
	if game.Workspace.time.Value == 0 then
		local e = math.random(1,2)
		
		if e == 1 then
			choice = map2
		end

		if e == 2 then
			choice = map1
		end
		
		game.Workspace.time.Value = 30
		choice:Remove()
		wait(3)
		choice.Parent = game.Workspace
	end
end

sorry for gross code I was tired when I made this lol, (and im decently new to scripting) the event is fired every second

1 answer

✓ Accepted answer

Hello!

I didn't understood much, but I think I found the problem.

local function changed()
    if game.Workspace.time.Value <= 0 then
        local e = math.random(1,2)

        if e == 1 then
            choice = map2
        end

        if e == 2 then
            choice = map1
        end

        game.Workspace.time.Value = 30
        -- choice:Remove()
        task.wait(3) -- use task.wait instead of wait.
        choice.Parent = game.Workspace
    end
end

You :Remove the choice, then parenting it to workspace, for whatever reason. Theorethically, it should fix the problem, altrough you might need a cleanup function. Also I changed if game.Workspace.time.Value == 0 then.

2 comments

0

Forgot to mention that :Remove is deprecated

0

the choice:remove part was the cleanup function, the problem was that I guess I ran the selector too early meaning that it would pick a map, remove the map, then try to set it's workspace like you said, so thanks for responding!

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