‘’’’
local station = script.Parent
local train1 = workspace.Train_1:GetDescendants()
local train = workspace:FindFirstChild(“Train_1”)
local debounce = false
local train_1 = game.Workspace.Train_1
local stationValue = 0
local occupiedValue = station.occupiedValue.Value
–if Train1 or Train2 has hit then
function stationHit(hit)
local ancestor = hit:FindFirstAncestor(“Train_1”)
if ancestor then
if not debounce then
debounce = true
print(“Train1 has been stopped at exit”)
script.Parent.CanCollide = true – brick collide is on-- train is anchored
for _,v in pairs(train1) do
if v:IsA(“BasePart”) then
v.Anchored = true
end
wait(5)
debounce = false
stationValue = 1
while(stationValue == 1) do
if stationValue and occupiedValue == 1 then
debounce = true
print(“Train 1 has been departed from the exit”)
script.Parent.CanCollide = false
for _,v in pairs(train1) do
if v:IsA(“BasePart”) then
v.Anchored = false
end
wait(5)
debounce = false
end
end
end
end
else
print("No train is at the exit")
end
end
end
if stationValue == 1 and occupiedValue == 1 then
debounce = true
print(“Train 1 has been departed from the exit”)
script.Parent.CanCollide = false
for _,v in pairs(train1) do
if v:IsA(“BasePart”) then
v.Anchored = false
end
wait(5)
debounce = false
stationValue = 0
end
end
station.Touched:Connect(stationHit)
–while station Value == 1–
–Debounce off
–Train anchored
–Collision Brick On
‘’’’
What I want in this script is for once a model is detected touching the block, then it anchors the model, puts the block on collision and then check for if the station value and occupied value is 1. If both values are 1 then, the model is unachnored and the block is put on non-collision. However, this doesn’t work. Can someone help me