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

Map Selection Script , but when i run the game, this error shows up and nothing happens?

Asked by 5 years ago

So i have this script for Map Selection for my Murder game which is in development. Once i run the game, there is only the "Slecting Map.." message who shows up and in Output i get this error saying "12:15:22.993 - Workspace.Script:25: attempt to call global 'selectMap' (a nil value)"

local replicatedStorage = game:GetService("ReplicatedStorage")
local maps = replicatedStorage:WaitForChild("Maps")

local function pickMap()
    local mapList = maps:GetChildren() -- Declares a table of the maps inside of the Maps folder.
    local selectedIndex = math.random(1,#maps) -- Choose a random number between 1, and the number of maps available.
    local map = mapList[selectedIndex]:Clone() -- Create a clone of the map we selected.
    map.Parent = workspace -- Parent it to the workspace.
    map.Name = "Map" -- Rename the map so that we can use the unloadMap() function later to remove it.
    return mapList[selectedIndex].Name -- Return the name of the map we selected, in case we want to display it.
end

local function unloadMap()
    if workspace:FindFirstChild("Map") then -- If there is a model in the Workspace named "Map"
        workspace.Map:Destroy() -- Destroy it!
    end
end

local h = Instance.new("Hint")
h.Parent = workspace

while true do
    h.Text = "Picking new map..."
    wait(3)
    local mapName = selectMap()
    h.Text = "Selected map: "..mapName
    wait(3)
    h.Text = "Unloading map..."
    unloadMap()
    wait(3)
end

1 answer

Log in to vote
0
Answered by
lunatic5 409 Moderation Voter
5 years ago

On line 25, you are calling a function that doesn't exist. You are trying to call the function "selectMap()". What you need to type on line 25 is "local mapName = pickMap()"

0
If this helps, please accept my answer! Thanks. lunatic5 409 — 5y
Ad

Answer this question