Sorry for the spam.
I am making a vent that unanchors itself when it is touched, but the script automatically enables itself because it is touching the surrounding walls. Here's what I have so far:
fall = script.Parent fall.Touched:Connect(function() fall.Transparency = 0 fall.CanCollide = true for _, object in pairs(fall.Parent:GetChildren()) do object.Anchored = false end end)
How would you make it so that the union only unanchors when a player or humanoid touches it and not all parts? Hopefully that made sense.
If you want to check if the thing that touches it is any humanoid, you can use FindFirstChildOfClass
to see if there is a Humanoid inside the parent of the thing that touched it:
script.Parent.Touched:Connect(function(Hit) if Hit.Parent:FindFirstChildOfClass("Humanoid") then print("Touched by a part from a model with a humanoid inside!") end end)
However, if you only wanted to check if the thing that touched was a character of a player, you can use GetPlayerFromCharacter
, which will return nil
if there is no player that owns the model:
script.Parent.Touched:Connect(function(Hit) local Plr = game.Players:GetPlayerFromCharacter(Hit.Parent) if Plr then print("Touched by " .. Plr.Name) end end)
Hope this helps!