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

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

Asked by 5 years ago

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)


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. popdrinkman 8 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

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)

Ad
Log in to vote
0
Answered by
Farsalis 369 Moderation Voter
5 years ago

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.

Answer this question