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