Advertisement
Er1x_Official

random item drop on death

Jan 5th, 2022
762
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.69 KB | None | 0 0
  1. -- variables vvv
  2. local Character = script.Parent
  3. local Humanoid = Character:FindFirstChildOfClass("Humanoid")
  4. local RootPart = Character:FindFirstChild("HumanoidRootPart") or Character:FindFirstChild("Torso") -- if root is non existant it would get the cframe of the torso
  5. local ServiceRS = game:GetService("ReplicatedStorage")
  6. local ItemFolder = ServiceRS:WaitForChild("Items") -- folder name
  7. -- configuration vv | note: dont enable isapart and isatool at the same time
  8. local ItemNames = {"Tool","MeshPart","Part"} -- item names, can use multiple (you could add duplicate names)
  9. local IsaPart = true -- if the item is a part/meshpart/union
  10. local IsaTool = false -- if the item is a tool
  11. local IsRandom = true -- set to true if you want it random
  12. local ItemName = "MeshPart" -- singular item
  13.  
  14. -- randomizer vvv
  15. function random(Position:CFrame,Parent)
  16.     local mat = #ItemNames
  17.     local item = ItemFolder:WaitForChild(ItemNames[math.random(1,mat)]):Clone() -- get the item from the folder & clone it
  18.     if IsaTool then
  19.         item.Handle.CFrame = Position -- cframe of the item(area of drop)
  20.         item.Parent = Parent -- parent of the item
  21.     elseif IsaPart then
  22.         item.CFrame = Position
  23.         item.Parent = Parent
  24.     end
  25. end
  26.  
  27. -- when player dies vvv
  28. Humanoid.Died:Connect(function()
  29.     if IsRandom then -- check if random is true or not
  30.         random(RootPart.CFrame,workspace)
  31.     else
  32.         local item = ItemFolder:WaitForChild(ItemName):Clone() -- get the item from the folder & clone it
  33.         if IsaTool then
  34.             item.Handle.CFrame = RootPart.CFrame -- cframe of the item(area of drop)
  35.             item.Parent = workspace -- parent of the item
  36.         elseif IsaPart then
  37.             item.CFrame = RootPart.CFrame
  38.             item.Parent = workspace
  39.         end
  40.     end
  41. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement