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

Brick won't load if I click my GUIButton?

Asked by
skyab12 25
7 years ago

So I made an open and close system and if you click for example "Map 1" button then the map1 brick will be cloned to workspace. The GUIs are in "StarterGui" and the brick that has to be loaded in is in a folder called "Maps" in ReplicatedStorage.

local TPS13B = game.StarterGui["GUi testing"].Frame.TPS13B
local ClickDetector = Instance.new("ClickDetector")
ClickDetector.Parent = game.StarterGui["GUi testing"].Frame.TPS13B
ClickDetector.MouseClick:connect (function(LOAD)

    local TPS13 = game.ReplicatedStorage.Maps.TPS13:Clone()
    TPS13.Parent= workspace
end)

Please tell me if I missed out on something or if I am wrong,etc..

1 answer

Log in to vote
3
Answered by
Bulvyte 388 Moderation Voter
7 years ago
Edited 7 years ago

You have made alot of mistakes.

local player = game.Players.LocalPlayer --define player
local gui = player.PlayerGui:WaitForChild("MapGui") --define where the gui is
local guibutton = gui.Button -- define gui's button
local repStorage = game:GetService("ReplicatedStorage") --get replicated storage

guibutton.MouseButton1Down:connect(function() -- now here we use MouseButton1Down for the gui, so when it's clicked we connect the function
    local map1 = repStorage.Maps.TPS13:Clone() -- let's clone the TPS13 from replicatedStorage's map's folder
    map1.Parent = game.Workspace -- set it's parent to game.Workspace NOTE that it's game.Workspace not workspace.
end)

ClickDetectors are for bricks, not GUIs. StarterGui is where you put all the guis and in online mode you don't need to modify things there, you modify the PlayerGui instead.

This is how your setup should look like: http://prntscr.com/can2ep

0
Actually, 'workspace' is valid and is the same as (and possibly prefered to) game.Workspace. IDidMakeThat 1135 — 7y
0
i haven't seen anyone use workspace Bulvyte 388 — 7y
0
but ok ill know that. Bulvyte 388 — 7y
Ad

Answer this question