Hi I’ve made a script which will put an image above users who are in a certain group and it all works properly.
The problem is that I keep getting an error on lines 14 and 35 whenever a player leaves which I believe is because the script is no longer able to find them.
My question is how am I able to fix this error?
I attempted to remove the character check and replace it with a wait so when the respawn is called the script will be able to find them once generated but this stops the script from working entirely.
Here is the code:
local groupID = 299014
local GroupService = game:GetService("GroupService")
local Players = game:GetService("Players")
local function onCharacterAdded(player)
local groups = GroupService:GetGroupsAsync(player.UserId)
for _, groupInfo in pairs(groups) do
wait(1)
local groupno = groupInfo.Id
if groupInfo then
if groupno == groupID then
local gui=Instance.new("BillboardGui")
gui.Parent=player.Character.Head
gui.Adornee=player.Character.Head
gui.Size=UDim2.new(3,0,3,0)
gui.StudsOffset=Vector3.new(0.5,2,0)
local text=Instance.new("ImageLabel")
text.Image = "rbxgameasset://Images/Photo"
text.Size=UDim2.new(1,0,1,0)
text.Position=UDim2.new(-0.225,0,-0.35,-45)
text.BackgroundTransparency = 1
text.Parent=gui
print(player.Name.. " is a member of the group")
end
end
end
end
Players.PlayerAdded:Connect(onCharacterAdded)
local function onPlayerRespawn(character)
character.Changed:Connect(function(property)
if (property == "Character") then
onCharacterAdded(character)
print("Reloading " ..character.Name.. "'s GUI.")
end
end)
end
Players.PlayerAdded:Connect(onPlayerRespawn)
