Server script not detecting remote event?

I’m trying to create a script that inserts a billboard GUI into a character’s head and destroys the GUI when it receives a server event. But, the server script that I’m using to destroy the billboard GUI isn’t detecting it. I’ve used print statements to try and debug this and it appears that the .OnServerEvent connection isn’t firing at all.

If anyone could help at all, it would be great. Cheers.

Local Script:

local oocGUI = game:GetService('ReplicatedStorage'):WaitForChild('oocGUI')

local rEvent = game:GetService('ReplicatedStorage'):WaitForChild('OOCEvent')

local ooc = false

local player = game:GetService('Players').LocalPlayer

local char = player.Character

local debounce = false

local RESET_SECS = 2


script.Parent.MouseButton1Down:Connect(function()

    if not ooc then 

        if not debounce then

            debounce = true

            ooc = true

            print('ooc Variable set to True')

            local cloneOOC = oocGUI:Clone()

            print('Clone made')

            cloneOOC.Parent = char.Head

            print('Clone parent set to character head')

            wait(RESET_SECS)

            debounce = false

        end

    else 

        ooc = false

        print('ooc variable set to False')

        rEvent:FireServer()

        print('RemoteEvent fired')

    end

end)

Script:

local RS = game:GetService('ReplicatedStorage')

local rEvent = RS:WaitForChild('OOCEvent')

local textLabel = script.Parent.TextLabel

local gui = script.Parent


rEvent.OnServerEvent:Connect(function()

    print('Event received')

    if gui.Parent.Name == "Head" then

        gui:Destroy()

    end

end)

Edit: After some careful examination of my code and with some help from the folks at ScriptingHelpers, I changed it to where the insertion and deletion of the billboard GUI is handled by the client. Thank you everyone who responded in an attempt to help.

I think that you’re missing the player parameter in the remote event received. This is a parameter automatically passed by Roblox and it is always the first parameter received in a server received event. Ex: revent.onserverevent:Connect(function(plr))

Also, check that the remote event you are trying to get actually exists. Are you getting any warnings about infinite waiting time for the event in the console?

As a general rule, things created on the client are not visible to the server for security reasons. Things inserted into characters may be an exception, I can’t remember off the top of my head. You can check in a studio test by playing solo, going into server view, and see if the Gui is visible there. I’m not in studio at the moment, otherwise I would just check.

Also, either your Gui needs to be secure and needs to be solely added/scripted on the server, or its security is unimportant and can be done on the client (if that’s even possible).

Typically, Gui’s are just done on the server and are replicated automatically through Roblox’s default server/client replicators. I would recommend just doing this on server scripts alone and not even using remote events. If you want to pass some option/configuration for the GUI from the client to the server, that’s fine, but I wouldn’t recommend this current setup.