Hope all is well. I’m currently having an issue with GetPlayerFromCharacter not functioning properly. Sometimes it works, sometimes it doesn’t, I’m not sure what to do. Can anyone help me, please? Thanks.
(Checks if player is found)
-- Variables
local touchPart = script.Parent.touch
local Players = game:GetService("Players")
touchPart.Touched:Connect(function(hit)
local character = hit.Parent
local player = Players:GetPlayerFromCharacter(character)
if player then
print(player.Name," is detected")
else
print("player is not detected")
end
end)
Alternate version
-- Variables
local touchPart = script.Parent.touch
local Players = game:GetService("Players")
touchPart.Touched:Connect(function(hit)
local character = hit.Parent
local player = Players:GetPlayerFromCharacter(character)
print(player.Name)
end)
Im assuming that the touch part is on top of the white part, which would mean that things like the hat and double blades on your characters back would touch the part, but their parent isn’t your character
I’m interested in knowing what hit is in these erroring lines. You can use the first snippet and replace the print where the player was not found with print(hit.Name).
Edit. Refer to Dragon_bloxy, they’re right, handles.