Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

Like The Mad Murder.

1 answer

✓ Accepted answer

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))

This discussion is preserved as it was. New answers, comments, and votes are closed.