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

when i click, the script does nothing. I recieve no output. can somebody help?

code:

local function click (player)
 player.PlayerGui.Hosvi.Frame.Visibility = true
print("cool")
end

script.Parent.ClickDetector.mouseClick:connect(click)

I have a click detector in the brick. I click and it does nothing. No output. No print. Nada

please help.

1 answer

✓ 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

0

thanks a lot my friend!

0

You are very welcome!

0

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")'

0

Did you change anything with the script?

0

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,

0

i didnt modify anything

0

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.

0

error from the local script: 19:55:49.893 - OnServerInvoke is not a valid member of RemoteEvent

0

try OnServerEvent instead

0

My bad, that is for RemoteFunctions.

0

Onserverevent can only be used by the server. you said "LocalScript in StarterPlayer"

0

OnClientEvent

0

It's late at night, please forgive me.

0

the local script doesnt do anything. where exactly do i put it?

0

StarterPlayer

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