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

can someone help me make a script that gives players ranomd items?

so im not good at scripting in fact I'm pretty sure a monkey knows more about it than I do so can someone walk me through how to make a script that gives players random items? and maybe make one? thanks!

1 answer

So, what I'm going to do is when you click a button, it gives you a random item.

Let's get started:

1.Insert a 'Folder' in ServerStorage and rename it to 'Items'. 2.Insert all of your items in the 'Items' folder and make sure they're tools 3.Insert a 'LocalScript' in StarterPlayerScripts which is located in StarterPlayer. 4.Insert a 'ScreenGui' in StarterGui. 5.Insert a 'TextButton' in the 'ScreenGui'. 6.In the 'LocalScript' copy the following code:

local minNum = 1
local totalItems = 3 --total items
local rng

local itemFolder = game.ReplicatedStorage.Items
local Client = game.Players.LocalPlayer 
wait(5)

local ScreenGui = Client.PlayerGui.ScreenGui
local TextButton = ScreenGui.TextButton

--more of this number variables if you have more items
local ShotgunPos = 1
local SniperPos = 2
local AssaultRiflePos = 3

local function RandomItemGenerator()
    rng = math.random(minNum, totalItems)
 
    --more of these 'if statements' if you have more items

    if rng == ShotgunPos then
        local shotgunClone = itemFolder.Shotgun:Clone()
        shotgunClone.Parent = Client.Backpack 

    elseif rng == SniperPos then
        local sniperClone = itemFolder.Sniper:Clone()
        sniperClone.Parent = Client.Backpack

    elseif rng == AssaultRiflePos then
        local assaultRifleClone = itemFolder.AssaultRifle:Clone()
        assaultRifleClone.Parent = Client.Backpack

    end
end

TextButton.MouseButton1Click:Connect(RandomItemGenerator)

This code kinda works out. More items make it more random.

If you think it's good, you can make this the solution, but there are many ways to do this which is better than mine.

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