✓ Accepted answer
Hello! You have multiple problems in your code that need to be fixed.
First off, please use :Connect instead of :connect, as it is deprecated.
Second of all, :MouseClick is the way to use a click detector.
local function click (player)
player.PlayerGui.Hosvi.Frame.Visibility = true
print("cool")
end
script.Parent.ClickDetector.MouseClick:Connect(player)
Now, if you were to do the script above, you would still be having problems.
FilteringEnabled is a setting in which the Client cannot change anything in the Server, which is good to protect against hackers. It is highly recommended to keep this setting turned on, so you would need to use RemoteEvents to fix your problem.
You want to have a server event tell the client to do something, a.k.a, a ClickDetector opening a GUI. RemoteEvents help talk to the server about that.
Server Script:
local event = Instance.new("RemoteEvent")
event.Parent = game:GetService("ReplicatedStorage")
event.Name = "ClickEvent"
local function click (player)
event:FireClient(player)
print("Clicked")
end
script.Parent.ClickDetector.MouseClick:Connect(click)
LocalScript in StarterPlayer
local player = game:GetService("Players").LocalPlayer
local event = game:GetService("ReplicatedStorage"):WaitForChild("ClickEvent")
local function clickEvent()
player.PlayerGui.Hosvi.Frame.Visibility = true
end
event.OnServerEvent:Connect(clickEvent)
This should be some working code, if you need any help with getting it to work, or want to know how it works, please ask!
15 comments
thanks a lot my friend!
You are very welcome!
i do need help setting it up tho. i was doing a couple of other things and then i realized the script didnt work: error is 19:05:00.016 - Infinite yield possible on 'ReplicatedStorage:WaitForChild("ClickEvent")'
Did you change anything with the script?
The first 3 lines of the first script sets up the RemoteEvent, which the line that isn't working is looking for. You could always add it in yourself if it isn't working,
i didnt modify anything
Well, like said before, delete the first 3 lines in the first script. Then, create a RemoteEvent in ReplicatedStroage and name is ClickEvent. Then see if it works.
error from the local script: 19:55:49.893 - OnServerInvoke is not a valid member of RemoteEvent
try OnServerEvent instead
My bad, that is for RemoteFunctions.
Onserverevent can only be used by the server. you said "LocalScript in StarterPlayer"
OnClientEvent
It's late at night, please forgive me.
the local script doesnt do anything. where exactly do i put it?
StarterPlayer