After adding my last thing in my game, I realized the touch event is not firing. I have no clue as to why it isn’t firing when it is 100% touching another part. Although, I wouldn’t be surprised if its because of the way I scripted the movement of the part. My script won’t print “Touched” and I see no errors.
What Im Trying to do: There is a part which is controlled by the player. The player can move this part, and touch other parts. It wont register when it is touching another part.
Touched Script:
PlayerCube.Touched:Connect(function(Toucher)
print("Touched")
if Debounce then
Debounce = false
local FoodMass = Toucher:FindFirstChild("FoodMass")
local PlayerMass = Toucher:FindFirstChild("PlayerMass")
if FoodMass then
PlayerCube.PlayerMass.Value += FoodMass.Value
Toucher:Destroy()
UpdateSize()
elseif PlayerMass then
if PlayerCube.PlayerMass.Value > PlayerMass.Value then
PlayerCube.PlayerMass.Value += PlayerMass.Value
local PlayerDied = Players:FindFirstChild(Toucher.Name)
if PlayerDied then
PieceEvents.Died:FireClient(PlayerDied, Player)
end
Toucher:Destroy()
UpdateSize()
end
end
Debounce = true
end
end)
Movement Script:
local Cube = workspace:FindFirstChild(Player.Name)
if Cube then
local Speed = Cube.Speed.Value
if GoForward == true then
Cube.Position = Vector3.new(Cube.Position.X, Cube.Position.Y, Cube.Position.Z - Speed)
end
if GoBackward == true then
Cube.Position = Vector3.new(Cube.Position.X, Cube.Position.Y, Cube.Position.Z + Speed)
end
if GoLeft == true then
Cube.Position = Vector3.new(Cube.Position.X - Speed, Cube.Position.Y, Cube.Position.Z)
end
if GoRight == true then
Cube.Position = Vector3.new(Cube.Position.X + Speed, Cube.Position.Y, Cube.Position.Z)
end
end
There is a part which is controlled by the player. The player can move this part, and touch other parts. It wont register when it is touching another part.
ROBLOX only checks for collisions when at least one of the objects is rendered by physics. If you re-position the cube, it doesn’t count as it moving. It’s still considered as a static object to the physics engine. It’s how the physics engine optimizes on performance. (Doesn’t apply collisions and physics on static objects with no movement/velocity)
You could use a Region3 and gather all parts that are within the cube’s range. That’s the most convenient fix to your problem right now.
For reference on which appropriate function to use, check out FindPartsInRegion3
That will create a Region3 cubic area from the part’s center position and expand it to all edges of your cube. (Luckily you’re using a cube in this scenario)
From there, you can call FindPartsInRegion3, there’s also an optional whitelist or ignorelist that can be added to filter out objects. Of course, whitelists should be used if possible over ignorelists, as whitelists save performance and checks for collisions with the provided parts.
The method returns an array (table) of all parts within the bounding box of your Region3 A.K.A the cube’s size.
I need help. I’m trying to have a part move to another part(which works) but it doesn’t fire the touch event.
its like it touches the other part but ignores touch event
im basically trying to create music maker with a time scrubber (part1)that touches all the notes (part 2)
its supposed to play a note when part1 touches it but it doesnt
script.Parent.Touched:connect(function(hit)
if hit.Name == game.Workspace.noteblock:FindFirstChild(“music”) then – change this
game.Workspace.noteblock.Music:Play()
end
end)
does this has something about is not firing touch event when its moving?
In case if the issue wasn’t already resolved by all this time,
From what I see, the issue might be in you trying to compare the name of a part to another instance
if hit.Name == game.Workspace.noteblock:FindFirstChild(“music”) then
Are you trying to compare the names of both objects?
If yes then try this
script.Parent.Touched:connect(function(hit)
if hit.Name == game.Workspace.noteblock:FindFirstChild(“music”).Name then – change this
game.Workspace.noteblock.Music:Play()
end
end)
I have a similar problem, but the part that uses the touched event is welded to another that is being tweened and is anchored, The touch part acts like a hitbox around the moving part, but it only detects player models(characters or rigs) and not parts, unions or other models, and I checked that the parts I want to detect are not anchored, but still nothing.