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 10 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.

game.Players.PlayerAdded:connect(function(plr)
plr.CharacterAdded:connect(function(chr)
local hk = Instance.new("BoolValue", plr)
hk.Value = false
hk.Name = "HoldingKnife"
local m = 0
repeat
wait()
if hk==true then
local hum = chr:FindFirstChild("Humanoid")
if hum then
hum.Died:connect(function()
hk.Value = false
end)
end
return
else
hk.Value = true
local o = math.random(1,4)
if o==1 then
local clone1 = game.Lighting.Blade:Clone()
clone1.Parent = plr.Backpack
elseif o==2 then
local clone2 = game.Lighting.Bombos:Clone()
clone2.Parent = plr.Backpack
elseif o==3 then
local clone3 = game.Lighting.DualKnives:Clone()
clone3.Parent = plr.Backpack
elseif o==4 then
local clone4 = game.Lighting.InsaneKnife:Clone()
clone4.Parent = plr.Backpack
end
end
until m==10
end)
end)

1 answer

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

use Tables and math.random

Item1 = game.Lighting.ItemName
Item2 = game.Lighting.ItemName
Item3 = game.Lighting.ItemName --and keep doing this until u have all the Items defined
Items = {Item1, Item2, Item3} --Put all of the above Names inside

--onSpawn Code (ur Code is a lil confusing, sry)
SpawnItem = Items[math.random(#Items, 1)] --sry, didn't use Tables with math.random in ages now
SpawnItem: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 — 10y
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 — 10y
0
also, wat u mean interesting? lol KAAK82 16 — 10y
Ad

Answer this question