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

Why is my tool printing when it's touching player that it's not touching player?

There are no syntax problems, but it is printing 'touching workspace and not player' when it is touching player and I don't know how I can counteract that.

My main question is how do I detect all the blocks that are touching the handle (which is a tool in the starterpack) and make it print something, and if it is touching a player (me) it will do nothing? It is printing touching workspace (which refers to blocks in workspace) and not player, but it is printing that because it is touching player.

Tool = script.Parent
Tool.RequiresHandle = true
Tool.GripPos = Vector3.new(0,0,1.5)

Tool.Handle.Touched:Connect(function(hit)
	if hit.Parent and not hit.Parent:FindFirstChild("Humanoid") then
		print("touching workspace & not player")

	else
		print("touching player")
	end
end)


1 comment

0

You were also correct, I just accepted the other answer because it was specific to the player and I learned more from it. Thanks for your help though I definitely appreciate it.

2 answers

✓ Accepted answer

Try:

local Tool = script.Parent
Tool.RequiresHandle = true
Tool.GripPos = Vector3.new(0,0,1.5)

-- if this isn't a local script change this
local Player = game.Players.LocalPlayer

Tool.Handle.Touched:Connect(function(hit)
    if hit.Parent and hit.Parent:FindFirstChild("Humanoid) then
		if not hit:IsDescendantOf(Player.Character) then
			print("Touched a part that's not the local player")
			print(hit.Name) -- to confirm what part is being hit
		end
	end
end)

Well, actually you code is right. The problem is the grip-pos. Since as far as the handle is concerned its touching the base-plate/parts. So in actuality its touching the ground or a part. Not the player.

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