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

How to randomise Character using Starter Character or Any other ideas?

Asked by 4 years ago

So I am messing around with an idea I had and I want to make it so every time you die your character changes between the four characters that I have in RepStorage.

I have a basic idea of I have to use Math.Random and put it into StarterPlayer and name it starter Character but I am not too great using Math.Random so I am not sure what I would do here or where to put the scripts.

If someone could help me out that'd be great!

1 answer

Log in to vote
0
Answered by
SteamG00B 1633 Moderation Voter
4 years ago

I was about to answer this when cloudflare got hit, but anyway, it's given me time to think about this, and I believe the best way to do it is as follows:

So in rep storage, you have 4 character models, all named "StarterCharacter", keep them in a folder named something like Characters. Then in your script, do something like this:

(this is mostly pseudocode, you will have to polish it to your specifications)

local chars = RepStorage.Characters:GetChildren()
game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
        StarterPlayer.StarterCharacter:Destroy()
        chars[math.random(1,4)]:Clone().Parent = StarterPlayer
    end
end

So you get a table of all the characters using getchildren, and then when a player's character loads in, you destroy the old one and get a new model in so that it preps it for the next time the character loads in. This way you don't need to handle anything with loading the character in yourself.

0
Where do you put the script? User#36987 0 — 4y
0
Thanks (: SyncSim 4 — 4y
0
Jonny, I never provided a script, that is only pseudocode, anyway, where you put your scripts should never change. Always keep them in server scripts. It's there for a reason. SteamG00B 1633 — 4y
Ad

Answer this question