Script in click detector doesnt fire remote event

I am trying to make a script in a click detector fire a remote event to the client and turn on a Gui,
but for some reason, the remote event is not fired, the part detects the click but i dont receive any output from the console.

The reason why i am not putting everything in one local script in the gui is because there are many parts with the same name and it cant detect the specific one that the player clicked.

(The local script is inside starterplayerScripts)

here is my code:

click detector script:

local detector = script.Parent

local RS = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")

local RV = RS:WaitForChild("SeedsGuiClose")

detector.MouseClick:Connect(function(plr)
	print("Clicked!")
	
	RV:FireClient(plr)

(the code then continues but doesnt affect the previous)

local script (inside starterPlayerScripts):

local RS = game:GetService("ReplicatedStorage")
local RV = RS:WaitForChild("SeedsGuiClose")


function on(player)
	print("Here")
	player:WaitForChild("PlayerGui"):WaitForChild("ScreenGui").Enabled = true
	print("pastHere")
end


RV.OnClientEvent:Connect(function(on)
end)

The only thing that it appears in the output is the “Clicked!” message

1 Like

First of all, you should not be using abbreviations for variables or anything in general. You will come back to this code in a day or week and have trouble figuring out what anything does, it also makes it a pain to troubleshoot.

Secondly, the issue is that :fireClient() is for use by server scripts. Since you are not crossing the client-server boundary you should be using Bindable events instead.

1 Like

Is the script printing ‘Clicked!’ server or client?

1 Like

First off, you do not need to fire the player instance to the client, as you already have the player instance from the client.

To fix this i would try something like:


local player = game.Players.LocalPlayer
local player_gui = player:WaitForChild("PlayerGui")

local RS = game:GetService("ReplicatedStorage")
local RV = RS:WaitForChild("SeedsGuiClose")


function on()
	print("Here")
	player_gui:WaitForChild("ScreenGui").Enabled = true
	print("pastHere")
end


RV.OnClientEvent:Connect(function(on)
end)

You could also disable gui’s on the server entirely like so:

local detector = script.Parent

local RS = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")

local RV = RS:WaitForChild("SeedsGuiClose")

detector.MouseClick:Connect(function(plr)
	local plr_gui = plr:WaitForChild("PlayerGui")
        local screen_gui = plr_gui:WaitForChild("ScreenGui")
        screen_gui.Enabled = false

Though i believe this may have some confusion between client-to-server if you try to enabled it from the client again.

Please do reply back if this does or does not solve your issue.

2 Likes

i tried this but it didnt work,i didnt get any output from the prints in the local script

its in the server script that is inside the click detector

Thanks for the feedback i will stop using abbreviations from now on.

:fireClient() is in a server script inside a click detector

The remote is firing, its how your receiving it that’s wrong:

RV.OnClientEvent:Connect(function(on)
end)

this just calls a new function with the parameter on, instead you should do:

RV.OnClientEvent:Connect(on)
1 Like

Thank you very much, this worked perfectly

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.