You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
im trying to make a zombie drop certain items when it dies
What is the issue? Include screenshots / videos if possible!
it works only for the first two items and the rest of the code doesnt seems to do anything
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
tried setting the cframe or setting the position and something is wrong. also tried to place items in server storage
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local tn = script.Parent.Parent;
local dropitems =
{"cash","mediuma","heavya","cash","corpse","cash","corpse","corpse","lighta","corpse"}
local chosen = dropitems[math.random(1,#dropitems)]
script.Parent.Died:connect(function()
if chosen == "cash" then
local item = game.ReplicatedStorage.Cash10:Clone()
item.Parent = game.Workspace--place item parent
item.Position = script.Parent.Parent.UpperTorso.Position
elseif chosen == "corpse" then
wait(5)
local item = game.ReplicatedStorage.Corpse:Clone()
item.Parent = game.Workspace--place item parent
item:SetPrimaryPartCFrame(script.Parent.Parent.UpperTorso.CFrame)
elseif chosen == "lighta" then
local item = game.ReplicatedStorage.smallammo.Clone()
item.Parent = game.Workspace--place item parent
item.Position = script.Parent.Parent.UpperTorso.Position
elseif chosen == "mediuma" then
local item = game.ReplicatedStorage.MediumAmmo.Clone()
item.Parent = game.Workspace--place item parent
item:SetPrimaryPartCFrame(script.Parent.Parent.UpperTorso.CFrame)
elseif chosen == "heavya" then
local item = game.ReplicatedStorage.LargeAmmo:Clone()
item.Parent = game.Workspace--place item parent
item.Position = script.Parent.Parent.UpperTorso.Position
end
wait(10)
tn:remove()
end)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
Seems like “cash” and “corpse” are significantly more likely than the last few since they have multiple entries. still should work, though you might have to do more tests to see ammo show up
Try printing the chosen value right after “local chosen = dropitems[math.random(1,#dropitems)]”
this should atleast let you know if it actually picks other things from the list aswell
Is everything that could spawn anchored?
edit: I checked and it seems to work fine picking a random value but I also mostly get corpse and cash as these are the most common in the list, temporarily change the chosen value to what you’d like to test to see if the spawning actually works so you don’t have to keep hoping for the math.random to get it, once you see it works you can use math.random again