So i’m working on a game where I want some people to be red some people to be blue, and some green. I’m trying to do that using math.random, yet there’s two problems…
With the script below it’s only giving GREEN avatars (you can see my humanoid descriptions below) however I want it to give either of the three.
I feel this isn’t even efficient enough for what I want, is there anyway to make 1/3 red, 1/3 blue, and 1/3 green?
Any help would be appreciated :^)
game.Players.CharacterAutoLoads = false
local avs = game:FindService("ReplicatedStorage").ColorsAvs.Default:GetChildren()
local int = math.random(#avs)
local randav = avs[int]
local function onPlayerAdded(player)
if player.Name == "ollieryz" then
player:LoadCharacterWithHumanoidDescription(game.ReplicatedStorage.ColorsAvs.VIPAv)
else
player:LoadCharacterWithHumanoidDescription(randav)
end
end
game.Players.PlayerAdded:Connect(onPlayerAdded)
You have to randomize it inside your onPlayerAdded function. Right now it should be random, but it’ll only randomize once - so everyone who joins your game gets the same color
In your script, you only choose the colour once. So when a player joins, it will return the same color for all players who join. As for it being only green, I think thats because you only set a maximum number, and not a minimum. So it returns the last value in the array
Simplified
Add the random choosing into the OnPlayerAdded function, and then add the number 1 followed by #avs in your int variable.
Edit: Someone got to the function part before me, but yeah, still add a minimum
No worries! All players go into a game with a bool called “CanLoadCharacterAppearence”. Just switch it off and you’re all good. If you’re tying to set the respawn time, thats also changeable in the humanoid as well as the location. The respawn time is set to 7 by default.
As you can see by my script ive done game.Players.CharacterAutoLoads = false, meaning they shouldn’t be respawning, I don’t quite understand what you’re saying.
Since you disabled CharacterAutoLoads, Therefore players don’t spawn in the first place.
All you have to do is:
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
char.Humanoid.Died:Connect(function()
wait(yourDuration)
plr:LoadCharacter()
end)
end)
plr:LoadCharacter() --load em in for the first time
end)
Sorry, Completely went over that. But, this should work:
local function onPlayerAdded(player)
if player.Name == "ollieryz" then
player:LoadCharacterWithHumanoidDescription(game.ReplicatedStorage.ColorsAvs.VIPAv)
else
player:LoadCharacterWithHumanoidDescription(randav)
end
player.CharacterAdded:Connect(function(char)
char.Humanoid.Died:Connect(function()
wait(3)
player:LoadCharacter()
end)
end)
end
went ahead and tested it and works completely fine.