Hi again,
So, in accordance with my map voting system, I want to have players (who are, earlier on, assigned to their respective teams) be teleported on the map that was voted for and spawn at their respective spawn points. However, the problem I have is that my round module script doesn’t understand what “ClonedMap” is even though it’s a global variable, and I’m struggling to find a way to generalise each map into a similar variable so that when the variable is called, the map that was voted for is the one that loads in all actuality.
For background information, I have three scripts; voting and round modules, and a game script as the main one. To begin with, we shall go into my voting module script. At the end of this script, the string values of the names of maps (e.g. Crossroads) are displayed to the player via surface guis, and the highest voted (or randomly picked if no one votes) is referred to as “MapName”. Subsequently, I’ve made a function that MapName refers to the name of the map/model in replicated storage defined by that variable, and is returned to the game script as “ChosenMap”. See below for a clearer delineation:
local MapName = MapBoards["Map".. string.gsub(HighestVoted.Name, "MapVote", "")].MapGUI.MapName.Text
VotingStatus.StatusGUI.Status.Text = MapName .. " has been voted"
print(MapName)
wait(1) -- Time it takes for map to load when voting complete
function module.GrabMap()
local Maps = game.ReplicatedStorage:GetChildren()
local ChosenMap = game.ReplicatedStorage.Maps:FindFirstChild(MapName)
return ChosenMap
end
return end
end
Note: Please bear in mind that this code is part of a “while true do” loop, hence the “return end” phrase that stops the repeating voting cycle.
That said, I define ChosenMap in the game script by calling the above function, then clone it and place it in the workspace.
local ChosenMap = Voting.GrabMap()
print(ChosenMap)
ClonedMap = ChosenMap:Clone()
ClonedMap.Parent = game.Workspace
This now brings me to the issue I’m facing - teleporting players to the spawns on the map - in the round module script.
for i,v in pairs(Players) do
if v.Team == game.Teams["MALWARE"] then
v.Character.HumanoidRootPart.CFrame = game.Workspace.ClonedMap.MALWARESpawn.CFrame + Vector3.new(0,5,0)
elseif v.Team == game.Teams["Agents"] then
v.Character.HumanoidRootPart.CFrame = game.Workspace.ClonedMap.AgentSpawn.CFrame + Vector3.new(0,5,0)
end
If this block of code were to run, my character will be teleported to the coordinates 0,0 as it doesn’t understand what ClonedMap is.
So, to elaborate as best I can, how do I create a generalised variable for each of the maps, such as using ClonedMap, as opposed to replacing that variable with each map name, such as Crossroads, etc like this:
for i,v in pairs(Players) do
if v.Team == game.Teams["MALWARE"] then
v.Character.HumanoidRootPart.CFrame = game.Workspace.Crossroads.MALWARESpawn.CFrame + Vector3.new(0,5,0)
Using the above code, the following results:
However, if I do, indeed, use this code, it would mean I would have to create subsequent conditional statements (e.g. if Crossroads is in the workspace, then discontinue the line of code that would put Haunted Mansion in the workspace, etc. etc), but I don’t desire this. This is because, even though the Haunted Mansion map wouldn’t enter the workspace, there is an error in the output and I don’t want to create unnecessary, unused code. I’m putting this topic out here as I’m certain there’s a far more efficient system that any of you out there may know of.
Therefore, is there some way to return the ClonedMap variable from the game script to the round module script, or is there an alternative way to generalise the maps as one variable and have the map enter the workspace when that variable is called?
I hope I’ve explained everything well because it’s the best I’m able to delineate as a beginner developer, but I appreciate any advice you have and I’m open to providing more detail if required.