Spawn Map script is not working

Hello!
I am trying to make a TextButton when i click on it, spawn a map.
The script is not working for some reason.

-- Script inside TextButton
local Folder = game.Lighting.Folder
local TextButton = script.Parent.Name
local Model = game.Lighting.Folder.TextButton
script.Parent.MouseButton1Click:Connect(function()
	Model.Parent = game.Workspace
end)
2 Likes

TextButton is String
but your code:

local Model = game.Lighting.Folder.TextButton

should be:

local Model = game.Lighting.Folder[TextButton]
3 Likes

Hm. It still shows this
error

1 Like

your meant to make local model = blablabla the location of the map for example local model = game.Lighting.Folder.Map1

1 Like

can you show your Explorer? for more details

1 Like

lighting

1 Like

also i used this local script to clone text buttons

local Folder = game.Lighting.Folder
for i, v in pairs(Folder:GetChildren()) do
	if v:IsA("Model") then
		local TextButton = script.Parent.TextButton:Clone()
		TextButton.Parent = script.Parent
		TextButton.Name = v.Name
		TextButton.Text = v.Name
	end
end
1 Like

can you show your Explorer while you play in studio?

1 Like

gfhdfhg
idk
they clones

1 Like

also player gui:
plrgui

1 Like

Try this instead for the getting the model:

local Model = Folder:FindFirstChild(TextButton);

or better to overcome any replication issues:

local Model = Folder:WaitForChild(TextButton,3);
1 Like

try this:

local Lighting = game:GetService("Lighting")

local Folder = Lighting.Folder
local Button = script.Parent
print("Button name is:",Button.Name,"\nnow check if Folder has ",Button.Name)
local Model = Folder[Button.Name]

function onMouseButton1Click()
	Model.Parent = workspace
end

Button.MouseButton1Click:Connect(onMouseButton1Click)
1 Like

image

1 Like

What is the Text of the button you clicked?

1 Like

JumpingTrouble is the Name of the Text Button and the Text i clicked

1 Like

Maybe it’s because the script is LocalScript?

local Folder = game.Lighting.Folder
for i, v in pairs(Folder:GetChildren()) do
	if v:IsA("Model") then
		local TextButton = script.Parent.TextButton:Clone()
		TextButton.Parent = script.Parent
		TextButton.Name = v.Name
		TextButton.Text = v.Name
		--other properties here
	end
end
1 Like

Are you using server script and localscript?
or just localscript?
Will your game be single player?

1 Like

clone and spawn script must be ServerScript, not localScript

1 Like

No the game won’t be single player. Like if host click Spawn Map on the Text Button, it changes [MapName].Parent = game.Workspace

1 Like

It worked for me when i used
SomeMap.Parent = game.Wokspace
and now since im using the clone its not working anymore

1 Like