[FIXED!] Billboardgui not enabling on another player

Hello developers,

I am trying to make a system when a player dies and the player is a chef he loses the chef rank, everything works perfectly it’s just that the GUI doesn’t enable when the chef rank is switched to another player
Here’s the script:

local deathevent = game.ReplicatedStorage.Death

game.Players.PlayerAdded:Connect(function(plr)
local character = plr.CharacterAdded:Wait()

local head = character.Head

local humanoid = character:FindFirstChild(“Humanoid”)

local billboardguiclone = game.ServerStorage.BillboardGui:Clone()

billboardguiclone.Parent = head

end)

deathevent.OnServerEvent:Connect(function(plr)
local character = plr.CharacterAdded:Wait()

local head = character.Head

local humanoid = character:FindFirstChild(“Humanoid”)

local billboardguiclone = game.ServerStorage.BillboardGui:Clone()

billboardguiclone.Parent = head
end)

local players = game:GetService(“Players”)

local currentChef = nil

local function chooseRandomChef()
local playerList = players:GetPlayers()
if #playerList > 0 then
return playerList[math.random(1, #playerList)]
end
return nil
end

local function chef()
if currentChef == nil then
currentChef = chooseRandomChef()

  workspace.Chef.Value = currentChef.Name

  print(currentChef.Name.. " is the chef")
  
  local character = currentChef.CharacterAdded:Wait()

  local head = character.Head

  local humanoid = character:FindFirstChild("Humanoid")

  local billboardgui = head:FindFirstChild("BillboardGui")

  billboardgui.Enabled = true

end
end

game.Players.PlayerAdded:Connect(function(player)
if not currentChef then
chef()
end
end)

deathevent.OnServerEvent:Connect(function(plr)

currentChef = nil

  if currentChef == nil then
  	currentChef = chooseRandomChef()

  	workspace.Chef.Value = currentChef.Name
  	
  	print(currentChef.Name.. " is the new chef")
  	
  	local character = currentChef.CharacterAdded:Wait()

  	local head = character.Head

  	local humanoid = character:FindFirstChild("Humanoid")

  	local billboardgui = head:FindFirstChild("BillboardGui")

  	billboardgui.Enabled = true

end
end)

game.Players.PlayerAdded:Connect(function(plr)
workspace.Chef.Changed:Connect(function()
if workspace.Chef.Value == plr.Name then
local character = plr.CharacterAdded:Wait()

  local head = character.Head

  local humanoid = character:FindFirstChild("Humanoid")

  local billboardgui = head:FindFirstChild("BillboardGui")

  billboardgui.Enabled = true
  end

end)
end)

2 Likes