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

how to activate a gui when you click on a brick/w clickdetector?

Asked by 6 years ago

its a localscript also its in starterplayerscripts

01local GUI = UI local Button = GUI.Button
02local player = game.Workspace.localPlayer
03local repStorage = game:GetService("ReplicatedStorage")
04local remote = repStorage:FindFirstChild("ButtonClick")
05mouse = player:GetMouse()
06local idoit = game.Workspace.CHING.ClickDetector
07UI = game.StarterGui.KiKidied.tooxtbutton --idk why i named it that no judge
08 
09idoit.MouseButton1Click:Connect(function()
10 
11local frame = GUI.Frame
12 
13Button.MouseButton1Click:Connect(function() frame.Visible = true end)
14end)

2 answers

Log in to vote
0
Answered by
oilsauce 196
6 years ago
Edited 6 years ago

If you want a Frame to be visible when you click on a ClickDetector, all you have to fix is

1idoit.MouseButton1Click:Connect(function()
2 
3local frame = GUI.Frame
4frame.Visible = true -- The frame becomes visible when 'idoit' (the ClickDetector) is clicked.
5end)

Also, you should probably use the WaitForChild() function when you're getting something from the StarterGui, or other places. It'll wait until the thing you want exists.

1idoit.MouseButton1Click:Connect(function()
2 
3local frame = GUI.Frame
4frame.Visible = true -- The frame becomes visible when 'idoit' (the ClickDetector) is clicked.
5end)
1local GUI = game.StarterGui:WaitForChild("KiKidied"):WaitForChild("tooxtbutton") -- this will throw a warning if there is no such object as 'KiKidied' in StarterGui, or if there is no such object as 'tooxtbutton' in KiKidied.
2local Button = GUI.Button
3local player = game.Workspace.LocalPlayer
4local repStorage = game:GetService("ReplicatedStorage")
5local remote = repStorage:FindFirstChild("ButtonClick")
6mouse = player:GetMouse()
7local idoit = game.Workspace.CHING.ClickDetector

You shouldn't really put two WaitForChild() functions in in a row, but to not modify your script too much, I made the script wait until there is an object named 'KiKidied' in StarterGui. Then it'll wait until there is an object named 'tooxtbutton' in 'KiKidied'.

I hope this helped, I was a bit sleepy when I wrote this, you're free to ask any questions.

0
it tells me"infinite yield possible" and "localscript is not a valid member of players" also here is the scriptlocal player = game.Workspace.localPlayer local repStorage = game:GetService("ReplicatedStorage") local remote = repStorage:FindFirstChild("ButtonClick") mouse = player:GetMouse() local idoit = game.Workspace.CHING.ClickDetector UI = game.StarterGui.KiKidied.Frame --idk why i named it tha natonator63 29 — 6y
0
Crap, I misspelled it. It's LocalPlayer, and if it gives you an 'infinite yield possible' error, it means that it doesn't have the object in the desired place. oilsauce 196 — 6y
Ad
Log in to vote
0
Answered by
angeI1001 123
6 years ago

You can use a RemoteEvent for that, which you can find here: https://www.robloxdev.com/api-reference/class/RemoteEvent

Answer this question