Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make a Random Character Loader?

Asked by 4 years ago
Edited 4 years ago

I have recently ran into a problem with using "Custom Characters" in my game using StarterCharacters and ReplicatedStorage.

How the game is meant to work:

The player joins, The script get activated, The script gets a RANDOM Model named "StarterCharacter" In ServerStorage, The Model get implemented and is now the characters Avatar.

What happens if the Character resets?

The script runs again choosing a different "StarterCharacter" In ServerStorage.


I used this code in the following:

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)

I'm an Absolute beginner so any help is appreciated! :)

Link to the Characters: https://web.roblox.com/library/4665690727/

Answer this question