Hi! So I was trying to make a track placement system, and right now, I’m making it so if something is intersecting it, it won’t place. However, it randomly triggers, even when nothing is blocking it:
As you can see, nothing is blocking it, but I am still getting warned. Here’s my code:
local tracks = game.ReplicatedStorage.Tracks
local buttons = {}
local currentPoint = workspace.Start.Hit.CFrame
local lastPlacedTrack
for i, v in ipairs(script.Parent:GetChildren()) do
if v.ClassName == "TextButton" then
table.insert(buttons, v)
end
end
for i, button in ipairs(buttons) do
button.Activated:Connect(function()
local trackType = button.Text
local trackToClone = tracks[trackType]
-- The test track is to determine if something is intersecting with the new track that we want to place.
-- If there is, don't place the track
local testTrack = trackToClone:Clone()
testTrack.Parent = game.Workspace
testTrack:PivotTo(currentPoint)
local collisions = testTrack.TrackModel:GetTouchingParts()
local isBlocked = false
-- Loop through every part touching it. If it's name is TrackModel, check if it was the last placed track.
-- If it isn't, set IsBlocked to true.
for i, part in collisions do
if part.Name == "TrackModel" then
if part ~= lastPlacedTrack then
isBlocked = true
end
end
end
testTrack:Destroy()
if isBlocked == true then
warn("Tracks cannot intersect")
else
local newTrack = trackToClone:Clone()
newTrack.Parent = game.Workspace
newTrack:PivotTo(currentPoint)
currentPoint = newTrack.EndPos.CFrame
lastPlacedTrack = newTrack
end
end)
end
The reason I check if it’s name is TrackModel is because the tracks look like this:
If anyone knows a solution, please tell me!