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