i have this script and i wanna make it so that creates roads everytime the player enters or touched the detect part, it should’ve generate a straight roads
only problem is that it only generated once and never agian
theres no errors aswell so i dont know what’s the problem of it.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RoadFolder = workspace:FindFirstChild("RoadFolder")
local RoadTemplate = workspace:FindFirstChild("RoadTemplate")
local Detect = RoadTemplate:FindFirstChild("Detect")
local EndPoint = RoadTemplate:FindFirstChild("EndPoint")
local NumberValue = ReplicatedStorage:FindFirstChild("NumberValue")
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
local function CreateRoad(previousEndPoint)
local RoadClone = RoadTemplate:Clone()
local DetectClone = RoadClone:FindFirstChild("Detect")
local EndPointClone = RoadClone:FindFirstChild("EndPoint")
RoadClone:SetPrimaryPartCFrame(CFrame.new(previousEndPoint.Position))
RoadClone.Parent = RoadFolder
RoadClone.Name = "Road " .. NumberValue.Value
NumberValue.Value = NumberValue.Value + 1
if DetectClone and Humanoid then
DetectClone.Touched:Connect(function()
if #RoadFolder:GetChildren() > 1 then
CreateRoad(EndPointClone)
end
end)
DetectClone.TouchEnded:Connect(function()
if #RoadFolder:GetChildren() == NumberValue.Value + 1 then
RoadClone:Destroy()
end
end)
end
end
if Detect and Humanoid then
Detect.Touched:Connect(function()
if #RoadFolder:GetChildren() == 0 then
CreateRoad(EndPoint)
end
end)
end
end)
end)