I want a touch function that will return both the player that touched it, and the part that touched it. This is because I have a thing I made that needs to know if the correct tool hit it while still needing the players name.
My Example Script
script.Parent.Touched:Connect(function(part, player)
print(player.." has touched "..part)
end
If you just want to find the player that touched the part, you can use this:
local function GetPlayerFromHit(hit)
local player
if hit.Parent:FindFirstChild("Humanoid") then
player = game.Players:GetPlayerFromCharacter(hit.Parent)
end
return player
end
script.Parent.Touched:Connect(function(hit)
local player = GetPlayerFromHit(hit)
end)
edit: I mistyped something, but this should be fine now