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

What to use instead of 'getPlayer'?

Asked by 9 years ago
script.Parent.Touched:connect(function(Part)
    if Part.Parent:FindFirstChild("Humanoid") then
        local player=getPlayer(Part.Parent)
        game.ReplicatedStorage.Tool:clone().Parent=player.Backpack
    end
end)

I wouldn't know what to use instead of 'getPlayer' for the third line of code as it says it is an unknown. I was attempting to create a script that would clone a tool into the player's backpack on touch of a specific brick.

2 answers

Log in to vote
3
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

You're looking for the GetPlayerFromCharacter method of game.Players:

script.Parent.Touched:connect(function(Part)
    if Part.Parent:FindFirstChild("Humanoid") then
        local player=game.Players:GetPlayerFromCharacter(Part.Parent)
        game.ReplicatedStorage.Tool:clone().Parent=player.Backpack
    end
end)
0
Thank you so much! Zamperini 5 — 9y
Ad
Log in to vote
3
Answered by 9 years ago

Try using the GetPlayerFromCharacter method of Players

The script below should fix your issue:

script.Parent.Touched:connect(function(Part)
    if Part.Parent:FindFirstChild("Humanoid") then
    local player=game.Players:GetPlayerFromCharacter(Part.Parent)
        game.ReplicatedStorage.Tool:clone().Parent=player.Backpack
    end
end)

If my answer helped you, accept and upvote it. If not, please tell me the error message in the comments below.

Answer this question