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

my part wont print "PartTouched" when touched(By humanoid)?

Asked by 4 years ago

script.Parent.Touched:Connect(function(hit) hit:FindFirstChild("humanoid") print("PartTouched end)

No errors, it just says part touched when ****Anything**** touches it

1
Make sure you used an if statement. If hit.Parent:FindFirstChild("Humanoid") JesseSong 3916 — 4y

3 answers

Log in to vote
0
Answered by 4 years ago

Because you have to put hit.Parent:FindFirstChild("humanoid") and also fix print print ("PartTouched)

0
Please use a code block, you'd also need an if statement to check wether a character model hits a brick. JesseSong 3916 — 4y
Ad
Log in to vote
0
Answered by
DevingDev 346 Moderation Voter
4 years ago

This one is a bit unclear to me what you're trying to achieve, but if you want to make it so only the Player can touch the Part then you can use the :GetPlayerFromCharacter function.

-- Services
local playersService = game:GetService("Players")

script.Parent.Touched:Connect(function(hit)
    local player = playersService:GetPlayerFromCharacter(hit.Parent)
    if player then
        local character = player.Character
        local humanoid = character:FindFirstChild("Humanoid")

        print("Touched by player...")
    end
end)

Log in to vote
0
Answered by
JesseSong 3916 Moderation Voter Community Moderator
4 years ago
Edited 3 years ago

Your code only has one issue. You didn't use an if statement to check whether the humanoid hits something.

script.Parent.Touched:Connect(function(hit)


    if hit.Parent:FindFirstChild("Humanoid") then

    print( hit.Parent.Name .. "Has touched the brick"

end
end)

Refined grammatical errors. Date: February 19, 2021

0
If you have anymore messages, feel free to message me. JesseSong 3916 — 4y

Answer this question