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

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

Asked by 3 years ago
Edited 3 years ago

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

Log in to vote
0
Answered by 3 years ago

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

0
Or do what he did instead. KixWater 126 — 3y
0
Yeah this helped ty darkstar2121a 13 — 3y
Ad
Log in to vote
0
Answered by
KixWater 126
3 years ago

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.

0
This didn't fix it but ty anyway darkstar2121a 13 — 3y
0
Oh, welp no problem! KixWater 126 — 3y
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 darkstar2121a 13 — 3y
0
Oh ok no problem! KixWater 126 — 3y

Answer this question