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

[SOLVED] 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)

3 comments

0

Are you ever setting the ooc variable in your local script to true? Because this should definitely be working if you do.

0

Yeah, on Line 24 the ooc variable is being set to true.

0

using :Clone() on the client won't copy server scripts. thus the script is not copied into the billboard gui, if you are creating the gui on client, why not destroy it on client too?

1 answer

Found out I could do it by just using a handler to insert the GUI and destroy it when a serverEvent is called. Sharing code for others who are trying to do this.

Local Script:

local RS = game:GetService('ReplicatedStorage')

local oocEvent = RS.OOC:FindFirstChild('oocEvent')

local handlerEvent = RS.OOC:FindFirstChild('OOCHandler')

local playerService = game:GetService('Players')

local player = playerService.LocalPlayer

local char = player.Character

local debounce = false

local resetSECS = 2

local ooc = false


script.Parent.MouseButton1Down:Connect(function()
    
    if not ooc then
        
        if debounce then return end
        
        debounce = true
        
        ooc = true
        
        handlerEvent:FireServer()
        
        wait(resetSECS)
        
        debounce = false
        
    else 
        
        ooc = false
        
        oocEvent:FireServer()
        
    end
    
end)

Handler:

-- OOC Variable(s)

local RS = game:GetService('ReplicatedStorage')

local OOC_Handler_Event = RS.OOC:WaitForChild('OOCHandler')

local OOC_Event = RS.OOC:WaitForChild('oocEvent')

local OOC_GUI = RS:WaitForChild('oocGUI')

-- OOC Handler Event(s)

OOC_Handler_Event.OnServerEvent:Connect(function(plr)
    
    local clone = OOC_GUI:Clone()
    
    clone.Parent = plr.Character.Head
    
    local char = plr.Character
    
    for _,v in ipairs(char:GetChildren()) do

        if v:IsA("BasePart") or v:IsA("Part") then

            if v.Name == "HumanoidRootPart" then

                v.Transparency = 1

            else 

                v.Transparency = 0.5       

            end


        end

    end

    for _,v in ipairs(char.Humanoid:GetAccessories()) do

        if v:IsA("Accessory") then

            for _,m in pairs(v:GetChildren()) do

                if m.Name == "Handle" then

                    m.Transparency = .5

                end

            end

        end

    end
    
end)


OOC_Event.OnServerEvent:Connect(function(plr)
    
    plr.Character.Head.oocGUI:Destroy()
    
    local char = plr.Character
    
    for _,v in ipairs(char:GetChildren()) do

        if v:IsA("BasePart") or v:IsA("Part") then

            if v.Name == "HumanoidRootPart" then

                v.Transparency = 1

            else

                v.Transparency = 0

            end

        end

    end

    for _,v in ipairs(char.Humanoid:GetAccessories()) do

        if v:IsA("Accessory") then

            for _,m in pairs(v:GetChildren()) do

                if m.Name == "Handle" then

                    m.Transparency = 0

                end

            end

        end

    end
    
end)

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