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

How to give players a random gun on spawn? [closed]

Asked by 4 years ago

Please include the code which you are trying to use, so the community will be better-equipped to help you with your problem.

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!

0
WeaponPool[math.random(1, #WeaponPool)]:Clone().Parent = Player.Backpack Ziffixture 6913 — 4y

Closed as Not Constructive by Gey4Jesus69

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

1 answer

Log in to vote
0
Answered by 4 years ago

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.

Ad