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

How do I find a Player through .Touched Event?

Asked by 8 years ago
Edited 8 years ago
touchez = false
function Burger(hit)
    if hit.Parent:findFirstChild("Humanoid") ~= nil then
if not touchez then
touchez = true  


script.Parent.Sound:Play()
script.Parent.Smoke.Enabled = true
wait(5)     
        PP = game.ServerStorage.Burger:clone()
        PP.Parent = game.Players.localPlayer.Backpack
script.Parent.Sound:Stop()
script.Parent.Smoke.Enabled = false
end
wait(3)
touchez = false

end
end
script.Parent.Touchy.Touched:connect(Burger)

I'm completely aware that .localPlayer in a script does not work. I just tried it hoping that it would work

I'm trying to copy a tool from my game ServerStorage and place it into the players backpack, but I don't know how to find that specific player through a .Touched script.

I could place the object inside the player's character, but I don't want to have the problem in which if the player was holding an item already then it'll overlap and possibly cause a problem.

What can I do?

0
Please learn to indent properly, it lets us understand your code faster and easier and thus lets you get better, faster help. GoldenPhysics 474 — 8y

1 answer

Log in to vote
0
Answered by
StoIid 364 Moderation Voter
8 years ago
Edited 8 years ago

You will need to use GetPlayerFromCharacter()

You will need to do:

hit.Parent:GetPlayerFromCharacter(LocationOfHitsPlayer)

If you want more information on how this works, you should look here:

Info On GPFC (GetPlayerFromCharacter)

Hope this helped!

0
OK, well, I'm not really understand on how I'd set it up. I'm getting this error every time. "GetPlayerFromCharacter is not a valid member of Model" RadioactiveP0P 44 — 8y
0
Did you make sure to do : instead of . ? StoIid 364 — 8y
0
No, no. Thank you I figured it out. I'll accept this answer. :) RadioactiveP0P 44 — 8y
0
No problem. StoIid 364 — 8y
0
@Stolid For future reference: :GetPlayerFromCharacter() is a function of Class/Players, not of BaseParts. Uglypoe 557 — 8y
Ad

Answer this question