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

Random Item Giver Script?

Asked by 11 years ago

Why won't this work? I want to give each player a random item on spawn.

Gives a random player an item when they spawn. Out of these four items. Rewrite the script if nessecary.

01game.Players.PlayerAdded:connect(function(plr)
02plr.CharacterAdded:connect(function(chr)
03local hk = Instance.new("BoolValue", plr)
04hk.Value = false
05hk.Name = "HoldingKnife"
06local m = 0
07repeat
08wait()
09if hk==true then
10local hum = chr:FindFirstChild("Humanoid")
11if hum then
12hum.Died:connect(function()
13hk.Value = false
14end)
15end
View all 36 lines...

1 answer

Log in to vote
-1
Answered by
KAAK82 16
11 years ago

use Tables and math.random

1Item1 = game.Lighting.ItemName
2Item2 = game.Lighting.ItemName
3Item3 = game.Lighting.ItemName --and keep doing this until u have all the Items defined
4Items = {Item1, Item2, Item3} --Put all of the above Names inside
5 
6--onSpawn Code (ur Code is a lil confusing, sry)
7SpawnItem = Items[math.random(#Items, 1)] --sry, didn't use Tables with math.random in ages now
8SpawnItem:clone().Parent = --however u want to contact the Player, if it's a Gui then 'LocalPlayer'

Hope I helped :D

0
Seems interesting, shouldn't the square bracket have a closing bracket too though? deaththerapy 60 — 11y
0
oh yeah lol... thnx for spooting that... I must have press ] so fast that I didnt even press it and just went on to Enter... lol KAAK82 16 — 11y
0
also, wat u mean interesting? lol KAAK82 16 — 11y
Ad

Answer this question