✓ Accepted answer
Errors: You can not access the PlayerGui because Gui's are set by the client. Maybe some Gui's created by the server you can access but most of the Gui's that we use is created with client.
You need to use RemoteEvents with FireClient
You can see RemoteEvents and FireClient on roblox wiki:
RemoteEvents/RemoteFunctions
FireClient
For this, you need to create a Remote Event, LocalScirpt, ClickDetector & Script
For first create a RemoteEvent and put it on Replicated Storage, now create a LocalScript and put it on StarterGui, on LocalScript located in StarterGui put this code:
repeat wait() until game.Players.LocalPlayer
local event = game:GetService("ReplicatedStorage"):WaitForChild("Event")
local plr = game.Players.LocalPlayer
event.OnClientEvent:Connect(function()
local gui = "BookGui"
plr.PlayerGui:WaitForChild(tostring(gui))
if plr["PlayerGui"]:FindFirstChild(tostring(gui)) then
local gui = plr["PlayerGui"][tostring(gui)]
gui.ImageLabel.Visible = true
gui.TextButton.Visible = true
end
end)
Or you can put it on GUI and put this code:
wait()
local event = game:GetService("ReplicatedStorage"):WaitForChild("Event")
event.OnClientEvent:Connect(function()
script.Parent.ImageLabel.Visible = true
script.Parent.TextButton.Visible = true
end)
Now create a Script and ClickDetector In your part and put this:
local event = game:GetService("ReplicatedStorage"):WaitForChild("Event")
local clickdetector = script.Parent.ClickDetector
clickdetector.MouseClick:Connect(function(plr)
event:FireClient(plr)
end)
Hope it helped!
1 comment
Oh my god it works ! Thank you so much