I am currently making the script for the train. So basically, when the driver pressed the key P, the train will be anchor and before the anchor it sets speed to 0. But at this point there is a problem, for the driver script we are using local and for the value change we use script. We use the value to make true and false easier. But when the driver pressed the p key it just changes the button color and train speed doesn’t change and anchor. Any solution or idea is appreciate!
localscript
UIS.InputBegan:Connect(function(key)
if key.KeyCode.Name == "P" then
if anchors.Value == false then
anchors.Value = true
script.Parent.FramePC.Conducetorssignals.Anchors.TextButton.BackgroundColor3 = Color3.new(0, 1, 0.882353)
elseif anchors.Value == true then
anchors.Value = false
script.Parent.FramePC.Conducetorssignals.Anchors.TextButton.BackgroundColor3 = Color3.new(0, 0.282353, 0.243137)
end
end
end)
Script
anchors.Changed:Connect(function()
if anchors.Value == true then
wait(0.5)
script.Parent.Parent.State.currentSpeed.Value = 0
script.Parent.Parent.State.reqSpeed.Value = 0
wait(1)
script.Parent.Parent.Carriage1.Main1.BodyVelocity.Velocity = Vector3.new(0, 0, 0)
script.Parent.Parent.Carriage2.Main1.BodyVelocity.Velocity = Vector3.new(0, 0, 0)
script.Parent.Parent.Carriage3.Main1.BodyVelocity.Velocity = Vector3.new(0, 0, 0)
script.Parent.Parent.Carriage4.Main1.BodyVelocity.Velocity = Vector3.new(0, 0, 0)
script.Parent.Parent.Carriage1.Collutionbasement.Anchored = true
script.Parent.Parent.Carriage2.Collutionbasement.Anchored = true
script.Parent.Parent.Carriage3.Collutionbasement.Anchored = true
script.Parent.Parent.Carriage4.Collutionbasement.Anchored = true
elseif anchors.Value == false then
wait(1)
script.Parent.Parent.Carriage1.Collutionbasement.Anchored = false
script.Parent.Parent.Carriage2.Collutionbasement.Anchored = false
script.Parent.Parent.Carriage3.Collutionbasement.Anchored = false
script.Parent.Parent.Carriage4.Collutionbasement.Anchored = false
end
end)