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

How can i get a random hat from lighting for when a player spawns?

Asked by 10 years ago

Like The Mad Murder.

1 answer

Log in to vote
0
Answered by
Destrings 406 Moderation Voter
10 years ago

First of all, storing instances in Lighting is not recommended, consider using ServerStorage instead.

You create a table and fill it with references to the hats, then you select a random item from the table, clone it and insert it in player's character.

hats = game.ReplicatedStorage.Hats:GetChildren() --Getting the references to the hats

game.Players.PlayerAdded:connect(function(ply)--Just handling the events
    ply.CharacterAdded:connect(function(char)
        local hat = hats[math.random(#hats)]:Clone()--Getting a random hat from the table and cloning it
        hat.Parent = char --Inserting it in the character
    end
end))
Ad

Answer this question