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

Giver relocating to backpack isn't working?

Asked by 10 years ago
local Giver = script.Parent
local Gear = script.Parent.Tool
function onTouch(Brick)
    local Player = Brick.Parent:findFirstChild("Humanoid")
    if (Player~= nil) then
        local Location = game:GetService('Players')
        local New = Gear:Clone()
        New.Parent = Location.Backpack --Problem is on this line
    end
end
Giver.Touched:connect(onTouch)

1 answer

Log in to vote
2
Answered by 10 years ago
local Giver = script.Parent
local Gear = script.Parent.Tool
function onTouch(Brick)
    local Player = Game.Players:GetPlayerFromCharacter(Brick.Parent) --Get the player from the hit,
    if Player and not Player.Backpack:FindFirstChild(Gear.Name) then
        local New = Gear:Clone()
        New.Parent = Player.Backpack 
    end
end
Giver.Touched:connect(onTouch)

Ad

Answer this question