So I created this script to give a player a Overhead Role GUI, as well as some tools. But for some reason, the “GuardRole” isn’t working. It deletes the overhead role GUI but then it doesn’t do anything else. I’ve checked and tried numerous ways and I don’t know why it isn’t working.
local ServerStorage = game:GetService("ServerStorage")
local DispatchRoleGUI = ServerStorage.OverheadRolesGUI.DispatchRole
local GuardRoleGUI = ServerStorage.OverheadRolesGUI.GuardRole
local DriverRoleGUI = ServerStorage.OverheadRolesGUI.DriverRole
local Whistle = ServerStorage.Tools.Whistle
local AvantixMobile = ServerStorage.Tools.AvantixMobile
local DispatchBaton = ServerStorage.Tools.DispatchBaton
local debounce = false
game.Workspace.OverheadGUIs.RemoteEvent.OnServerEvent:connect(function(player, cmd)
local backpack = player.Backpack
local WhistleFind = backpack:FindFirstChild("Whistle")
local AvantixMobileFind = backpack:FindFirstChild("AvantixMobile")
local DispatchBatonFind = backpack:FindFirstChild("DispatchBaton")
local ToolsToRemove = {WhistleFind, AvantixMobileFind, DispatchBatonFind}
if cmd == "DispatcherRole" then
if not debounce then
debounce = true
for i,v in pairs (player.Character.Head:GetChildren()) do
if v:IsA("BillboardGui")then
v:Destroy()
end
end
for _,v in pairs(ToolsToRemove) do
for i, tool in pairs(backpack:GetChildren()) do
if tool.Name == v.Name then tool:Destroy() end
end
end
local clonedgui = DispatchRoleGUI:Clone()
clonedgui.Parent = game.Workspace:WaitForChild(player.Name).Head
local clonedwhistle = Whistle:Clone()
clonedwhistle.Parent = player.Backpack
local clonedbaton = DispatchBaton:Clone()
clonedbaton.Parent = player.Backpack
wait(1)
debounce = false
end
elseif cmd == "DriverRole" then
if not debounce then
debounce = true
for i,v in pairs (player.Character.Head:GetChildren()) do
if v:IsA("BillboardGui")then
v:Destroy()
end
end
for _,v in pairs(ToolsToRemove) do
for i, tool in pairs(backpack:GetChildren()) do
if tool.Name == v.Name then tool:Destroy() end
end
end
local clonedgui = DriverRoleGUI:Clone()
clonedgui.Parent = game.Workspace:WaitForChild(player.Name).Head
wait(1)
debounce = false
end
elseif cmd == "GuardRole" then
if not debounce then
debounce = true
for i,v in pairs (player.Character.Head:GetChildren()) do
if v:IsA("BillboardGui")then
v:Destroy()
end
end
for _,v in pairs(ToolsToRemove) do
for i, tool in pairs(backpack:GetChildren()) do
if tool.Name == v.Name then tool:Destroy() end
end
end
local clonedgui = GuardRoleGUI:Clone()
clonedgui.Parent = game.Workspace:WaitForChild(player.Name).Head
local avantixclone = AvantixMobile:Clone()
avantixclone.Parent = player.Backpack
local whistleclone = Whistle:Clone()
whistleclone.Parent = player.Backpack
wait(1)
debounce = false
end
elseif cmd == "DeleteRole" then
if not debounce then
debounce = true
for i,v in pairs (player.Character.Head:GetChildren()) do
if v:IsA("BillboardGui")then
v:Destroy()
end
end
for _,v in pairs(ToolsToRemove) do
for i, tool in pairs(backpack:GetChildren()) do
if tool.Name == v.Name then tool:Destroy() end
end
end
wait(1)
debounce = false
end
end
end)