Why Game Prints "Hit" When No Player Is Present? (Printed In Wrong Place)

So I have this script here:

local Part = script.Parent

Part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		Part.Transparency = .9
		Part.CanCollide = false
		Part.GlassShatter = true  -- GlassShatter is particle emitter
		Part.GlassShatter.Rate = 100
		Part.GlassShatter.Life = NumberRange.new(1,1)
	end
end)

print("Hit")

local Part = game.Workspace.Part:ClearAllChildren()

When I run the game, it prints “hit” when no character is present, what may be the cause of this?

Because your printing hit outside of the function

Because you put the print at the end, it does not go with the function and prints on its own

Well, my function runs without any player present still.

Yeah but your asking why its printing out Hit, it’s because it’s not inside of the function when a player with a humanoid touches the part

What exactly are you trying to convey?

Alright. I’m trying to emit the particle when somebody steps on it and then make the particle disappear. I understand the mistake with the print, but the function seems to run when nobody hits it.

Is there anything else with a humanoid that could be touching the part?

I actually re-ran it and it seems to be doing the opposite actually. It won’t run the function entirely. It skips to the ClearAllChildren part.

put

after

but still above

text limit

Thanks, I fixed that, but now my problem is it won’t run the function entirely.

I think your confused, the stuff after the function (outside of it) can still run even though the part hasn’t been touched, try this script:

local Part = script.Parent

Part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		Part.Transparency = .9
		Part.CanCollide = false
		Part.GlassShatter = true  -- GlassShatter is particle emitter
		Part.GlassShatter.Rate = 100
		Part.GlassShatter.Life = NumberRange.new(1,1)
        print("Hit")
        local Part = game.Workspace.Part:ClearAllChildren()
	end
end)

Ah thanks, I realized it now that I re-ran that I split it up when I did not need to. :laughing: