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

How does one create a randomizer game? Me and my friend need help.

Asked by
PynMan 0
2 years ago

We are both new to scripting and decided to attempt to create a game which gives a random gun sword and miscellaneous item on each spawn. We have tried pretty much every tutorial we could find and none seem to work if anyone knows how to help us with this I would be very grateful. :)

0
Based off percentage or just plain random? Maximus1027 30 — 2y
0
Plain random PynMan 0 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

You could put all the weapons in a dedicated folder in ServerStorage or somewhere and use GetChildren() to get a table with all the weapons. You can use the math.random function to choose a random weapon from the table every time and clone it to the player

local ServerStorage = game:GetService("ServerStorage")
local Players = game:GetService("Players")

-- table with all the weapons
local allWeapons = ServerStorage.Weapons:GetChildren()

Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        -- whenever somebody spawns or respawns, this will run

        -- select a random weapon, from 1 (the beginning of the table) to the last value in the table, clone it, and put it in the player's backpack
        local randomWeapon = allWeapons[math.random(1, #allWeapons)]:Clone()
        randomWeapon.Parent = player.Backpack
    end)
end)
0
All right ill try that PynMan 0 — 2y
0
Where do i put the script? I'm assuming ServerScriptService PynMan 0 — 2y
0
Ok it worked tysm been trying for hours lol (for anyone viewing this thread wondering where to but the script just put it in workspace) PynMan 0 — 2y
0
You should put most server scripts in ServerScriptService unless the script is part of a model or something else that's in the world https://developer.roblox.com/en-us/api-reference/class/ServerScriptService OfficerBrah 494 — 2y
0
@PynMan, I recommend you accept @OfficerBrah's answer. This will let people know that this is a verified working answer and it will help increase his reputation on the site IAmNotTheReal_MePipe 418 — 2y
Ad

Answer this question