How do i make it so that this drop system only gives the item to a specific player?
Asked by
6 years ago Edited 6 years ago
This is a server script and what i'm trying to accomplish is, once an npc has been killed it will drop a part. Once the part has been picked up it will give them an item, in this case a sword i'm not sure how to do it but this was my attempt. The sword just doesn't clone into the Backpack.
02 | local serverStorage = game:GetService( 'ServerStorage' ) |
05 | local weapons = serverStorage:WaitForChild( 'Weapons' ) |
06 | local myHum = script.Parent:WaitForChild( 'Humanoid' ) |
07 | local myHead = script.Parent:WaitForChild( 'Head' ) |
10 | myHum.Died:Connect( function () |
11 | local dropChance = math.random( 0 , 3 ) |
12 | local itemChance = math.random( 0 , 5 ) |
14 | if dropChance = = 3 or 2 or 1 then |
15 | local p = Instance.new( 'Part' ) |
18 | p.Size = Vector 3. new( 3 , 3 , 3 ) |
19 | p.Position = myHead.Position |
20 | p.Parent = game.Workspace |
22 | p.Touched:Connect( function (hit) |
23 | if hit.Parent:FindFirstChild( 'Humanoid' ) and hit.Parent.Name ~ = script.Parent.Name then |
24 | local clone = weapons:WaitForChild( 'Sword' ):Clone() |
25 | clone.Parent = hit.Parent:FindFirstChild( 'Backpack' ) |