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

Brick won't load if I click my GUIButton?

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 comment

1 answer

✓ Accepted answer

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

3 comments

0

Actually, 'workspace' is valid and is the same as (and possibly prefered to) game.Workspace.

0

i haven't seen anyone use workspace

0

but ok ill know that.

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