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

How do i make it so that this drop system only gives the item to a specific player?

Asked by
Sorukan 240 Moderation Voter
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.

01--//Services
02local serverStorage = game:GetService('ServerStorage')
03 
04--//Variables
05local weapons = serverStorage:WaitForChild('Weapons')
06local myHum = script.Parent:WaitForChild('Humanoid')
07local myHead = script.Parent:WaitForChild('Head')
08 
09--//Died
10myHum.Died:Connect(function()
11    local dropChance = math.random(0,3)
12    local itemChance = math.random(0,5)
13 
14    if dropChance == 3 or 2 or 1 then
15        local p = Instance.new('Part')
View all 30 lines...
0
serverStorage should be game.ServerStorage also shouldnt hit.Parent.Name and script.Parent.Name have something between them? 129Steve129 7 — 6y

1 answer

Log in to vote
1
Answered by
hellmatic 1523 Moderation Voter
6 years ago
Edited 6 years ago

Backpack is a child of the player object. You were trying to find it under the player's character. You can get the player using GetPlayerFromCharacter:

01p.Touched:Connect(function(hit)
02    local parentModel = hit.Parent
03    if parentModel then
04        local player = game.Players:GetPlayerFromCharacter(parentModel)
05        if player then
06            local weapon = weapons:WaitForChild("Sword"):Clone()
07            weapon.Parent = player.Backpack
08            p:Destroy()
09        end
10    end
11end)
0
Oh, thanks! Sorukan 240 — 6y
Ad

Answer this question