Problem with deleting overhead guis script

Hello i got a problem with a script i need to make it like if you press delete roles button all overhead guis will be deleted from your head but for some reason it’s wont work where and what did i do wrong with a script?

here the code:

--local script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RolesEvents = ReplicatedStorage:WaitForChild("RolesDelete")

script.Parent.MouseButton1Click:Connect(function(player)
	RolesEvents:FireServer(player)
end)

--script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RolesEvents = ReplicatedStorage:WaitForChild("RolesDelete")
local Roles = {game.ServerStorage.Guis.Adoptus.Name, game.ServerStorage.Guis.Apostol.Name, game.ServerStorage.Guis.Daughter.Name, game.ServerStorage.Guis.General.Name, game.ServerStorage.Guis.HelperTehnoJrec.Name, game.ServerStorage.Guis.Imperator.Name, game.ServerStorage.Guis.KCK.Name, game.ServerStorage.Guis.LeftHandGod.Name, game.ServerStorage.Guis.LordGeneral.Name, game.ServerStorage.Guis.Moderator.Name, game.ServerStorage.Guis.Novostei.Name, game.ServerStorage.Guis.PlayerName.Name, game.ServerStorage.Guis.Shturmovik.Name, game.ServerStorage.Guis.Son.Name, game.ServerStorage.Guis.Tester.Name}

RolesEvents.OnServerEvent:Connect(function(player)
	for i, v in pairs(Roles) do
		game.Workspace:WaitForChild(player.Name).Head:WaitForChild(v):Destroy()
	end
end)

thanks for helping :flushed:

1 Like

Did you get any error?..

yes i got error

Infinite yield possible on ‘Workspace.Shakychn.Head:WaitForChild(“Adoptus”)’

Because Adoptus is not inside the Head.

MouseButton1Click has no parameters, and sending the player is unnecessary because OnServerEvent already has a player parameter. You just have to get rid of the player parameter and argument in the LocalScript to fix this issue.

Also MouseButton1Click doesn’t have player parameter

i know but i need to make it like delete every single overhead gui that player have on head but i dont know how to do that

I think i know what are you making.

So firstly try check if the overhead gui is in the player head.

RolesEvents.OnServerEvent:Connect(function(player)
	for i, v in pairs(Roles) do
         if game.Workspace:WaitForChild(player.Name):FindFirstChild(v) then
		    game.Workspace:WaitForChild(player.Name):FindFirstChild(v):Destroy()
         end
	end
end)

Edit: Fixed the indentation

now its not even giving me any error in output
and yeah you got me right

So does it work?..

no its still doesnt delete overhead guis

Could you make a picture of your explorer like that?

image

rwqr

Do you want the whole gui be deleted or just whats inside?

yeah i want whole gui to be deleted

RolesEvents.OnServerEvent:Connect(function(player)
	for i, v in pairs(player.Character.Head:GetChildren()) do
		if v:IsA("BillboardGui") then
			v:Destroy()
		end
	end
end)
1 Like

OMG! it’s finally worked! thanks you so much

1 Like

I know this is already solved, but I think using CollectionService for this might be considered :slight_smile:

You can tag the roles when they are created, then when you want to destroy them, just get everything with the tag and destroy it