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

How to give players a random gun on spawn?

So i began to create an Arsenal like game and so far so good however i have a problem. I don't know how to give players random guns on spawn. I searched on YouTube for ever and the only thing i found is tool giver by click. If you have time please give me the code. Have a great day/night, God bless you!

1 comment

0

WeaponPool[math.random(1, #WeaponPool)]:Clone().Parent = Player.Backpack

1 answer

Use the math.random function, which will return a number between two numbers specified.

local random = math.random(1,10) -- will return a random number between 1 and 10

So let's say you have a remote to spawn in and you have a module to equip the gun:

local loadCharacter = ... -- remote
local fpsModule = require(...) -- our module
local guns = ...:GetChildren() -- get all the guns inside some folder

loadCharacter.OnServerEvent:Connect(function(player)
	
	player:LoadCharacter() -- load the character aka. spawn
	
	local random = math.random(1,#guns) -- get a random number between 1 and the number of guns
	
	fpsModule:Equip(guns[random]) -- equip the gun
	
end)

I don't know if you're using modules or sum stuff like that, but I think this can guide you to adapt it to ur framework.

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