Hi, I am working on a custom admin script and want a script to be parented to the character every time it respawns. It only works when the player joins the game, but not when you respawn.
This is in a separate script
local function cloneStuff(plr)
local char = plr.Character
if not char:FindFirstChild('SyAdHandler') then
local handler = script:WaitForChild('SyAdHandler'):Clone()
handler.Parent = char
handler.Disabled = false
end
if not plr.PlayerGui:FindFirstChild('SnowAdminClient') then
local clientScript = script.Parent:WaitForChild('SnowAdminClient'):Clone()
clientScript.Parent = plr.PlayerGui
clientScript.Disabled = false
end
if not plr.PlayerGui:FindFirstChild('CameraInfo') then
local ccInfo = script.Parent:WaitForChild('CameraInfo'):Clone()
ccInfo.Parent = plr.PlayerGui
ccInfo.Disabled = true
end
if not plr.PlayerGui:FindFirstChild('CmdBar') then
local cmdBar = script.Parent:WaitForChild('Assets'):WaitForChild('CmdBar'):Clone()
cmdBar.Parent = plr.PlayerGui
cmdBar.Enabled = true
end
local isFlying = Instance.new('BoolValue', char)
isFlying.Name = 'isFlying'
isFlying.Value = false
end
game.Players.PlayerAdded:Connect(function(plr)
for i = 1, #config.rankNumbers do
if config.ranks[config.rankNumbers[i]] then
local rank = config.ranks[config.rankNumbers[i]]
if table.find(rank, plr.Name) or table.find(config.rankedPlayers, plr.UserId) then
plr.CharacterAdded:Connect(function(char)
task.wait()
cloneStuff(plr)
local ccInfo = plr.PlayerGui:WaitForChild('CameraInfo')
local handler = char:WaitForChild('SyAdHandler')
handler:SetAttribute('Rank', i)
if char:FindFirstChild('isFlying') then
char:FindFirstChild('isFlying'):GetPropertyChangedSignal('Value'):Connect(function()
if char:FindFirstChild('isFlying').Value == true then
ccInfo.Disabled = false
else
ccInfo.Disabled = true
end
end)
end
end)
end
end
end
end)
I tried to look up a solution on dev forum plus the wiki, but can’t seem to find a fix.