Hi, for my game i require players appearance to be randomised on respawn. I have 4 different characters for my game to choose from. So far i have this:
game.Players.PlayerAdded:connect(function(plr) plr.CharacterAdded:connect(function(char) local Characters = game:GetService("ReplicatedStorage").Players:GetChildren()[math.random(1,4)] print(Characters) if game:GetService("StarterPlayer"):FindFirstChild("StarterCharacter") then game:GetService("StarterPlayer").StarterCharacter:Destroy() end Characters.Name = "StarterCharacter" Characters.Parent = game:GetService("StarterPlayer") end) end)
Now this works, but not very accurate. Heres what happens in a nutshell. 1) Spawning (As my own avatar, SHOULD spawn as one of the 4 characters) 2) Reset 3) Spawn as ONE of the characters 4) Reset
What i want from this script is so that it will ALWAYS spawn as one of the 4 characters. Please help, Thanks :)
If you check well, you are inserting your rig in StarterPlayer. You're changing it when character is added, which won't put the character you randomised. To fix, you need to change the StarterCharacter when the Character is removed.
game.Players.PlayerAdded:connect(function(plr) local Characters = game:GetService("ReplicatedStorage").Players:GetChildren()[math.random(1,4)] 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,4)] if game:GetService("StarterPlayer"):FindFirstChild("StarterCharacter") then game:GetService("StarterPlayer").StarterCharacter:Destroy() end Characters.Name = "StarterCharacter" Characters.Parent = game:GetService("StarterPlayer") end) end)