Hello everyone,
In order to make sliding barriers for an airstairs model, but also be able to move the barriers with Motor6D, I’ve created disabled welds between it and another part that are enabled when the player decides to rotate the stairs. However, these welds move whenever I enable them when unanchoring the model.
Here’s a video of the problem.
As you can see, the panels move when I unanchor the vehicle.
Here’s my script.
local event = game:GetService("ReplicatedStorage"):WaitForChild("Airstairs")
local parts = script.Parent.OtherParts
local welds = script.Parent.WallWelds
local motors = script.Parent.Motors
local stgs = require(game:GetService("ReplicatedStorage"):WaitForChild("voltraAirstairsSettings"))
local anchor = true
local light = parts.Parent.Animations.Beams.LightBeam
local stairlights = light.Parent.Parent.Stairs
for i = 1, 60 do
motors:WaitForChild("Anchors").C1 = motors:WaitForChild("Anchors").C1 * CFrame.new(0,0.0025,0)
task.wait(0.001)
end
local cooldown = false
event.OnServerEvent:Connect(function(plr, action, boolean, instance)
if instance ~= script.Parent then return end
if cooldown then return end
print(plr.Name, "activated", action, boolean)
if plr:GetRankInGroup(stgs.securitySettings.groupID) >= stgs.securitySettings.staffRank then
if action == "Anchor" then
task.wait()
cooldown = true
local anchored = boolean
anchor = boolean
if anchored == false then
for i = 1, 60 do
motors:WaitForChild("Anchors").C1 = motors:WaitForChild("Anchors").C1 * CFrame.new(0,-0.0025,0)
task.wait(0.001)
end
motors:WaitForChild("Stairs").MaxVelocity = 0
motors:WaitForChild("Supports").MaxVelocity = 0
motors:WaitForChild("Platform").MaxVelocity = 0
-- PROBLEM AREA
for i, v in ipairs(welds:GetChildren()) do
if v:IsA("WeldConstraint") then
repeat
v.Enabled = true
task.wait()
until v.Enabled == true
print(v.Name, v.Enabled)
elseif v:IsA("MeshPart") then
repeat
v.Anchored = false
task.wait()
until v.Anchored == false
v:WaitForChild("DragDetector").Enabled = false
end
end
elseif anchored == true then
for i = 1, 60 do
motors:WaitForChild("Anchors").C1 = motors:WaitForChild("Anchors").C1 * CFrame.new(0,0.0025,0)
task.wait(0.001)
end
for i, v in ipairs(welds:GetChildren()) do
if v:IsA("WeldConstraint") then
repeat
v.Enabled = false
task.wait()
until v.Enabled == false
print(v.Name, v.Enabled)
elseif v:IsA("MeshPart") then
repeat
v.Anchored = true
task.wait()
until v.Anchored == true
v:WaitForChild("DragDetector").Enabled = true
end
end
end
for i, v in ipairs(parts:GetDescendants()) do
if v:IsA("MeshPart") then
v.Anchored = anchored
end
end
if motors.Handle.CurrentAngle == -1.4 then
light.Parent.Parent.Handle.Main.DragDetector.Enabled = not boolean
end
cooldown = false
elseif action == "Lower" then
if boolean == true then
task.wait()
if not anchor then return end
if cooldown then return end
for i, v in ipairs(welds:GetChildren()) do
if v:IsA("WeldConstraint") then
repeat
v.Enabled = true
until v.Enabled == true
print(v.Name, v.Enabled)
elseif v:IsA("MeshPart") then
repeat
v.Anchored = false
until v.Anchored == false
v:WaitForChild("DragDetector").Enabled = false
end
end
task.wait(0.1)
motors:WaitForChild("Stairs").MaxVelocity = 0.001
motors:WaitForChild("Supports").MaxVelocity = 0.0032
motors:WaitForChild("Platform").MaxVelocity = 0.001
for i, v in ipairs(motors:GetChildren()) do
if v:IsA("Motor6D") then
v.DesiredAngle = 0
end
end
elseif boolean == false then
task.wait()
if not anchor then return end
if cooldown then return end
for i, v in ipairs(motors:GetChildren()) do
if v:IsA("Motor6D") then
v.MaxVelocity = 0
end
end
task.wait()
for i, v in ipairs(welds:GetChildren()) do
if v:IsA("WeldConstraint") then
repeat
v.Enabled = false
until v.Enabled == false
print(v.Name, v.Enabled)
elseif v:IsA("MeshPart") then
repeat
v.Anchored = true
until v.Anchored == true
v:WaitForChild("DragDetector").Enabled = true
end
end
end
elseif action == "Raise" then
if boolean == true then
if not anchor then return end
if cooldown then return end
task.wait()
for i, v in ipairs(welds:GetChildren()) do
if v:IsA("WeldConstraint") then
repeat
v.Enabled = true
until v.Enabled == true
print(v.Name, v.Enabled)
elseif v:IsA("MeshPart") then
repeat
v.Anchored = false
until v.Anchored == false
v:WaitForChild("DragDetector").Enabled = false
end
end
task.wait(0.1)
motors:WaitForChild("Stairs").MaxVelocity = 0.001
motors:WaitForChild("Supports").MaxVelocity = 0.0032
motors:WaitForChild("Platform").MaxVelocity = 0.001
motors:WaitForChild("Stairs").DesiredAngle = 0.24
motors:WaitForChild("Supports").DesiredAngle = 0.785
motors:WaitForChild("Platform").DesiredAngle = -0.24
elseif boolean == false then
task.wait()
if not anchor then return end
if cooldown then return end
for i, v in ipairs(motors:GetChildren()) do
if v:IsA("Motor6D") then
v.MaxVelocity = 0
end
end
for i, v in ipairs(welds:GetChildren()) do
if v:IsA("WeldConstraint") then
repeat
v.Enabled = false
task.wait()
until v.Enabled == false
print(v.Name, v.Enabled)
elseif v:IsA("MeshPart") then
repeat
v.Anchored = true
task.wait()
until v.Anchored == true
v:WaitForChild("DragDetector").Enabled = true
end
end
end
elseif action == "Light" then
light.Beam.Enabled = boolean
light.SurfaceLight.Enabled = boolean
light.Material = Enum.Material.Neon
if boolean == true then
light.BrickColor = BrickColor.new("Institutional white")
else
light.BrickColor = BrickColor.new("Really black")
end
for i, v in ipairs(stairlights:GetChildren()) do
if v.Name == "Light" then
v.SurfaceLight.Enabled = boolean
end
end
end
end
end)
These are the welds causing the problem.
Does anyone know a solution to this? Any help is appreciated!