Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

if statements are stopping my function?

Asked by 1 year ago
Edited 1 year ago

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

Log in to vote
0
Answered by
SuperPuiu 497 Moderation Voter
1 year ago

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.

0
Forgot to mention that :Remove is deprecated SuperPuiu 497 — 1y
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! oXDestroyerXo 28 — 1y
Ad

Answer this question