Hello, I am trying to make it so that if a player is touching a part then it will set a value to true, if they are not then it sets it to false. Right now my code is setting it to true and then to false over and over.
If you can help, that’d be awesome!
Here is the code:
while true do
local children = Part:GetTouchingParts()
for i, child in ipairs(children) do
if child.Parent.Name == player.Name then
print("Player Is Touching")
isPlayer = true
else
print("Player Is NOT TOUCHING")
isPlayer = false
end
end
if breaker == true then
break
end
wait()
end
I believe :GetTouchingParts() does work with the .Touched function so this would obviously happen, whenever they are inside of it and not moving (like an animation or actual movement) the object is not being touched however when they are waking on it, it activates on and off alot. I still don’t see why Roblox hasn’t fixed this
Get the bounding box of the player (they’re a model in the workspace), get the position of the part you want to check isn’t being touched by the player, if the bounding box of the player’s character model and the part in question intersect then they are touching, otherwise they are not touching.
What you could do is place the part in a single model itself, then perform the GetBoundingBox function on both the model (which only contains the single part) and the character model.
Both of the functions do work, they just don’t behave in the way that you expect.
Touched is fired whenever a part touches another part.
TouchEnded is fired whenever a part is no longer touching another part after they have already touched.
There is no event which detects whether or not a part is not touching another part (if they haven’t already touched before).