Problem with track placement script

Hello, So I have been working on my upcoming game and I have run into a problem with the track PlacementScript.

In the track it has 2 main parts the “ConnectorPart” and the “JointPart”
Screenshot 2023-01-17 101647
Whats meant to happen is that when you place a track it will move the building part to the new track joint part and so on but for some reason it will only let me place one track.

I have tried many ways to fix this but I just can’t seem to.

Here is my script.

local TrackPlacementEvent = game.ReplicatedStorage:WaitForChild("TrackPlacementEvent")
local TrackFolder = game.ReplicatedStorage:WaitForChild("Tracks")

local BuildingPoint = game.Workspace:WaitForChild("SpawnTrack").JointPart
local NewBuildingPoint = false

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local TrackFrames = script.Parent.Parent.PlacementTracksFrame

local PlacingObject = false
local CanPlaceTrack = true

for i, TrackButtons in pairs(TrackFrames:GetChildren()) do
	if TrackButtons:IsA("Frame") then
			if not PlacingObject then
				if CanPlaceTrack == true then
					local PreviewTrack = TrackFolder:FindFirstChild(TrackButtons.Name):Clone()
					PreviewTrack.Parent = workspace
					local newBuildingPoint = PreviewTrack.JointPart
					if NewBuildingPoint == false then
					NewBuildingPoint = true

If you would like anymore information or screenshots feel free to ask

Thank you :slight_smile:

It appears that the issue is with the “NewBuildingPoint” variable not being correctly set when placing multiple tracks. The script sets the “NewBuildingPoint” variable to “true” after the first track is placed, but it is not being reset to “false” when a new track is placed. This means that on the second track placement, the script is using the previous track’s “JointPart” as the new building point, instead of the current track’s “JointPart”. To fix this issue, you should add a line to reset the “NewBuildingPoint” variable to “false” before setting it to “true” in the mouse button click event. Hope this helps. :sweat_smile: