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

How do I make random item selection?

Asked by 3 years ago

so basically I have 143 items and I want to randomly give the player five of these items when they spawn, but I can't figure it out. Right now the script does nothing for some reason. Right now it's in Starter Character Scripts.

What I have so far:

local Rstore = game.getservice("ReplicatedStorage")
local count = 0
local p = game.players.localplayer
while count >= 5 do
r = math.random(1,143)
    local Item = Rstore:GetChildren()
    local chosenItem = Item[math.random(1,143)]
    local GiveItem = chosenItem:Clone()
    GiveItem.parent = p.Backpack
    count = count + 1
end

0
Im not very good at scripting in general, so sorry if this doesn't help but, isn't players supposed to be Capitalized like "Players" and local players as "LocalPlayer"? Icy_limxz 14 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

Maybe its your capitalization, Lua is quite picky so that must be the case check you output bar for any errors, i can point out "players" to be "Players" and "localplayer" into "LocalPlayers" i can also see "getservice" you can turn into "GetService" unless you give me a error i can't really figure out much.

Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Change "getservice" to GetService, "players" to "Players" and "localplayer" to "LocalPlayer" as Lua is case-sensitive.

The While loop will not run as count(which is zero)>=5 is not true so change that to count<=5

Hope this helps

Answer this question