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

Why my GUI Image Labels wont show up using ClickDetector?

Asked by 5 years ago

I made a GUI Image Label in StarterGUI > ScreenGUI. I made a brick in Workspace and added a "Click Detector" to it. To the "Click Detector" I added a script.. I typed this in the script:

script.Parent.MouseClick:connect(function()
    game.StarterGui.ScreenGui.EarthMonitorOff.Visible = true --Tried to find the Image Label
    wait(1)
    game.StarterGui.ScreenGui.EarthMonitorOff.Visible = false
    game.StarterGui.ScreenGui.MonitorBootUp:Play()
    wait(0.01)
    game.StarterGui.ScreenGui.EarthMonitorOn.Visible = true
end)

I made 3 Image Labels but not even one works and shows up. I am clicking the button and all I hear is the audio I added in line 5. Thats all. Can anyone help me solve this? I tried looking for an solution but couldn`d find one that would help me and fix the problem.

0
connect is deprecated use Connect green271 635 — 5y
0
Doesn't works. HeyItzDanniee 252 — 5y
0
oh gee ok so the contents of startergui get copied into Player.PlayerGui, so for that you would have to get the players who clicked name and then do player.PlayerGui.EarthMonitorOff.Visible = true etc. radusavin366 617 — 5y
0
Also you can't change it from a server script. MythicalShade 420 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago

First of all, there would be no point in accessing the StarterGui as the GUI for the player is in the Whenever you want to do something GUI related, you have to do it in a LocalScript. So to do these GUI changes whenever you click the button, you will have to use a RemoteEvent.

First, put a RemoteEvent in ReplicatedStorage. Then, put a LocalScript inside inside of the ScreenGui.

Let's edit your server script inside of the part that you click.

script.Parent.MouseClick:Connect(function(player) -- connect is deprecated, player argument from mouseclick event
    local Event = game:GetService("ReplicatedStorage").RemoteEvent -- get RemoteEvent
    Event:FireClient(player) -- Fire the client
end)

Now in your LocalScript located inside the ScreenGui write the following code

local Event = game:GetService("ReplicatedStorage").RemoteEvent -- get RemoteEvent
Event.OnClientEvent:Connect(function() -- OnClientEvent Event fires when part is clicked
    script.Parent.EarthMonitorOff.Visible = true
    wait(1)
        script.Parent.EarthMonitorOff.Visible = false
        script.Parent.MonitorBootUp:Play()
        wait(0.01)
        script.Parent.EarthMonitorOn.Visible = true
end)

Now it should work.

Let me know if you have any more issues.

0
Alternatively if you wanted to change all Player's GUIs then you can just use "Event:FireAllClients()" Instead of "Event:FireClient(player)" MythicalShade 420 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Since you have put the ImageLabel inside of StarterGui you need to locate the PlayersGui > ScreenGui because everything you have in StarterGui will be replicated inside every players PlayerGui folder. Also you should reference the PlayersGui with something like this using there get service function. Also please use a local script when dealing with player gui or the player mouse or anything that is client related that can be done on the users computer.

local playerGui = game:GetService('Players').LocalPlayer:WaitForChild('PlayerGui')

-- reference other objects needed
local screenGui = playerGui:WaitForChild('ScreenGui')
local imageOne = screenGui:WaitForChild('EarthMonitorOff')
local imageTwo = screenGui:WaitForChild('EarthMonitorOn')

-- then use your image references like this
imageOne.Visible = false

-- hope this helped now try to complete your script with the info i gave you :)

Note: For ClickDetectors you will need to handle the mouse click event on the server so you will need a script for the ClickDetectors mouse click event and use a remote event and use the FireClient function to execute the local script for the PlayerGui changes.

Answer this question