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

[Beginner] how come my part wont print "hi" when touched?

Asked by 4 years ago

trying to make a touched function that before it prints "hi" it checks if 'hit' has a child named Break, but nothing works. how can i fix this problem? someone? Dora? Boots? Diego??

script.Parent.Touched:Connect(function(hit)
    if hit:FindFirstChild("Break") then
        print("hi")
    end
end)
0
is break a child of the part? WideSteal321 773 — 4y
0
no its a child of whatever's touching the part 10x31x2019 -6 — 4y
1
You might have to do hit.Parent:FindFirstChild because you want to check a model right? Skydoeskey 108 — 4y
0
Could you take a picture of your explorer? IvanJupiter 36 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

You could do this:

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Break") then
        print("hi")
    end
end)

I normally use this method as it is much more clear:

local part = game.Workspace.Break -- Define where the part is

local function OnTouched() -- Define a function that prints hi 
    print("hi")
end

part.Touched:Connect(OnTouched) -- Fires the function when part is touched
0
The part has to touch it, not you. and if it is touching it, check if Break is a child of the object which hit it ernestasviktorija 0 — 4y
0
part is inside whatever's touching the part with the touched function 10x31x2019 -6 — 4y
Ad

Answer this question