game.Players.PlayerAdded:Connect(function(plr)
local Characters =
game:GetService("ReplicatedStorage").Players:GetChildren()[math.random(1,9)]
if game:GetService("StarterPlayer"):FindFirstChild("StarterCharacter")
then
game:GetService("StarterPlayer").StarterCharacter:Destroy()
end
Characters.Name = "StarterCharacter"
Characters.Parent = game:GetService("StarterPlayer")
plr.CharacterRemoving:connect(function(char)
Characters =
game:GetService("ReplicatedStorage").Players:GetChildren()[math.random(1,9)]
if
game:GetService("StarterPlayer"):FindFirstChild("StarterCharacter") then
game:GetService("StarterPlayer").StarterCharacter:Destroy()
end
Characters.Name = "StarterCharacter"
Characters.Parent = game:GetService("StarterPlayer")
end)
end)
For me, there are no errors with your script. I organized it and it works perfectly fine?
game.Players.PlayerAdded:Connect(function(plr)
local Characters = game:GetService("ReplicatedStorage").Players:GetChildren()[math.random(1,9)]
if game:GetService("StarterPlayer"):FindFirstChild("StarterCharacter") then
game:GetService("StarterPlayer").StarterCharacter:Destroy()
end
Characters.Name = "StarterCharacter"
Characters.Parent = game:GetService("StarterPlayer")
plr.CharacterRemoving:connect(function(char)
Characters = game:GetService("ReplicatedStorage").Players:GetChildren()[math.random(1,9)]
if game:GetService("StarterPlayer"):FindFirstChild("StarterCharacter") then
game:GetService("StarterPlayer").StarterCharacter:Destroy()
end
Characters.Name = "StarterCharacter"
Characters.Parent = game:GetService("StarterPlayer")
end)
end)
That works, although the programming isn’t that great. I would use:
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local rand = math.random(1, 9)
if not game.StarterPlayer:FindFirstChildWhichIsA("Model") then
for i, v in pairs(game.ReplicatedStorage.Players:GetChildren())do
local isChosen = Instance.new("IntValue", v)
isChosen.Name = i
print(rand)
if v:FindFirstChild(rand) then
char:Destroy()
local clone = v:Clone()
clone.Parent = game.StarterPlayer
player:LoadCharacter()
end
end
end
end)
end)
This didn’t seem to work for me. I didn’t get any Errors. but the same Glitchy thing where I get stuck in another StarterCharacter keeps happening. (Screenshot in my Post)