Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

What to use instead of 'getPlayer'?

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

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)

1 comment

0

Thank you so much!

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.