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

Can someone fix this Map Changer script?

When I run the script everything runs perfectly fine until line 18.

local choices = {"Outpost", "Ravine"} --Put the maps in lighting, the names of each map go there.
local map = choices[math.random(1,#choices)]
local rtarget = game.Workspace.RedTargetPosition--Name a brick "RedTargetPosition" where you want red Team to be sent to at begining.
local btarget = game.Workspace.BlueTargetPosition--Name a brick "BlueTargetPosition" where you want blue Team to be sent to at begining.
local target2 = game.Workspace.LobbyPosition --Name a brick "LobbyPosition" where you want them to be sent to at the end.
while true do
	local m = Instance.new("Message", game.Workspace)
	m.Text = "Each round lasts five minutes, make the most of it." --Whatever you wanted it to say
	wait(2)
	m.Text = "A random map will be selected and both teams will be teleported to the map." --What do you want it to say?
	wait(2)
	m.Text = "You will have five minutes to kill your opponents. Good Luck and Have fun." --Change to whatever
	wait(2)
	for i = 5,1,-1 do
		wait(1)
		m.Text = "Selecting a map in ..i" --Countdown to when map is selected
	end
	map.Parent = Workspace
	map:MakeJoints() --ERROR HERE--
	m.Text = map.. "has been chosen!" --Shows which map got chosen
	wait(3)
	for i,v in pairs (game.Players:GetPlayers()) do
		if v ~= nil and v.TeamColor.Name == "Bright red" then
			v.Character.Torso.CFrame = rtarget.CFrame + Vector3.new(0,i*15,0)
		elseif v ~= nil and v.TeamColor.Name == "Bright blue" then
			v.Character.Torso.CFrame = btarget.CFrame + Vector3.new(0,i*15,0)
	wait(.1)
	end
print("Players teleported onto map") --Tells output they're on map
wait(300) --10 minutes
	for i,z in pairs (game.Players:GetPlayers()) do
		if z ~= nil then
			z.Character.Torso.CFrame = target2.CFrame + Vector3.new(0,i*15,0)
		end
	end
	end
end

Output says "Workspace.RandomizedMChanger:18: attempt to index local 'map' (a string value)"

1 answer

✓ Accepted answer

It is because Map is only indexed as a string value. You would want to do something along the lines of;

local spawnMap = game.Lighting:FindFirstChild(map)
spawnMap:Clone()
spawnMap.Parent = game.Workspace

2 comments

0

Where would I put this? Do I replace line 18 with the code you provided?

0

You wouldn't replace anything. Learn from the code and explanation I have provided, and implement it.

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