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

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

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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!

0
thanks a lot my friend! SodaZere 31 — 5y
0
You are very welcome! Creeperman1524 120 — 5y
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")' SodaZere 31 — 5y
0
Did you change anything with the script? Creeperman1524 120 — 5y
View all comments (11 more)
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, Creeperman1524 120 — 5y
0
i didnt modify anything SodaZere 31 — 5y
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. Creeperman1524 120 — 5y
0
error from the local script: 19:55:49.893 - OnServerInvoke is not a valid member of RemoteEvent SodaZere 31 — 5y
0
try OnServerEvent instead Creeperman1524 120 — 5y
0
My bad, that is for RemoteFunctions. Creeperman1524 120 — 5y
0
Onserverevent can only be used by the server. you said "LocalScript in StarterPlayer" SodaZere 31 — 5y
0
OnClientEvent Creeperman1524 120 — 5y
0
It's late at night, please forgive me. Creeperman1524 120 — 5y
0
the local script doesnt do anything. where exactly do i put it? SodaZere 31 — 5y
0
StarterPlayer Creeperman1524 120 — 5y
Ad

Answer this question