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

How can I fix a local script that is supposed to load maps but won't even run for some reason?

I'm currently making a half life mod in Roblox and I'm trying to make it so that if you press a button in the main menu it teleports you to a select map. I already wrote a script for this but for some reason the code just wont execute and I don't get anything in output. The script is a local script and is a child of StarterGUI. Here is the code:

--\Buttons/

local btn1 = game.StarterGui.menu.main.gm_prompt.lbl_troom -- training room button
local main = game.StarterGui.menu.main
local maps = game.ReplicatedStorage.maps
local cmap = workspace.current_map
local char = game.Players.LocalPlayer.Character
local hroot = char:WaitForChild("HumanoidRootPart")
--


--Map Loader--
btn1.MouseButton1Click:Connect(function()-- executed on click of troom button
	print("swear if it didn't work")
	cmap.spwn_box:Destroy() -- Destroys spawn box
	maps.c0p1.Parent = workspace.current_map
	main.Visible = false
	hroot.CFrame = maps.c0a1:WaitForChild("tp").CFrame
end)

Thanks in advance and sorry if its spaghetti I'm new and bad at coding

2 answers

✓ Accepted answer

Try putting the local script under the button and setting btn1 to script.Parent.

2 comments

0

Or do what he did instead.

0

Yeah this helped ty

You said it is in StarterGUI, right? Instead of doing.

local btn1 = game.StarterGui.menu.main.gm_prompt.lbl_troom

Try to do this instead.

local player = game.Players.LocalPlayer
local btn1 = player.PlayerGUI.menu.main.gm_prompt.lbl_troom

The reason why it may not work is because everything is copied from StarterGUI to the PlayerGUI so you need to access the PlayerGUI for it to work. If it still doesn't work, please comment back.

4 comments

0

This didn't fix it but ty anyway

0

Oh, welp no problem!

0

actually wait im an idiot so when I used the other guys code the tp worked but the menu stayed on the screen so when i used this it worked ty

0

Oh ok no problem!

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