(SOLVED BY @7z99 ! Solution at bottom of the post vv)
Hello,
I’ve run into a problem which I can’t find a solution for.
I’ve got this Title script in my game that shows above your head with your group rank, name etc.
The script works perfectly fine until I leave the game, then it sends an error message:
“Player:IsInGroup error: Player not in datamodel”
The original script isn’t mine, however I’ve lost the model from which it originated. The only thing I (think) I changed/added was the “device” thing. The device is found through a ModuleScript (if you need it then feel free to ask)
I’m not sure whether this will actually effect anything in the game (as I haven’t tested it much with other people), so it’s not top priority (yet)
This is what it looks like (it’s located inside of a Folder in ServerScriptService):
Aaand here’s the script:
local PlayerService = game:GetService("Players")
local groupId = 4673623 -- If testing this script, please also try using the id from a group that you have a rank in
local debounce = true
local device = require(script.RequireDevice)
function giveTitle(player)
if player then
if debounce then
debounce = false
wait(0.2)
if player:IsInGroup(groupId) then
local gui = script.TitleAboveHead:Clone()
workspace:WaitForChild(player.Name)
gui.Parent = player.Character.Head
gui.Adornee = player.Character.Head
player.Character.Humanoid.DisplayDistanceType = "None"
local t = gui.DisplayText
t.Name = "title-"..player.Name
if device == "Computer" then
device = "💻"
elseif device == "Mobile" then
device = "📱"
elseif device == "Console" then
device = "🎮"
elseif device == "VR" then
device = "🥽"
end
t.Text = device.." "..player.Name.." |"..player:GetRoleInGroup(groupId)
t.Parent = gui
end
wait(1)
debounce = true
else end
end
end
PlayerService.PlayerAdded:Connect(function(player)
giveTitle(player)
player.Changed:Connect(function(property)
if player and (property == "Character") then
wait(0.2)
giveTitle(player)
end
end)
end)
PlayerService.PlayerAdded:Connect(giveTitle)
Any help would be greatly appreciated!
(sorry for the long read )
Fix: add a line before if player:IsInGroup(groupId) then
with the content of local parent = player.Parent or player.AncestryChanged:Wait()