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

How do I make random item selection?

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

1 comment

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"?

2 answers

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.

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

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