Controlling constraints with script

I am trying to make a constraint move and then once the current-position reaches zero the next constraint will start moving. This is my current script but it will not work. I am using prismatic constraints
local P1 = script.Parent.P1
local P2 = script.Parent.P2
local P3 = script.Parent.P3
local P4 = script.Parent.P4
function start()

	P1.Speed = 4
	 if
		P1.CurrentPosition == 0
		then  
		
		P2.Speed = 4


	
	P2.Speed = 4
	P3.Speed = 4
	P4.Speed = 4

end
	end

start()

1 Like

The problem is that you’re running your start function once, so that it only checks the CurrentPosition of P1 once when the script runs.
You’d want to connect the function to when P1’s position changes, so that whenever the position changed, you’d be able to check if it’s 0. This can be done with GetPropertyChangedSignal.

Ex:

P1:GetPropertyChangedSignal("CurrentPosition"):Connect(start)
1 Like

hmm I will try this

says function start() is a error
local P1 = script.Parent.P1
local P2 = script.Parent.P2
local P3 = script.Parent.P3
local P4 = script.Parent.P4
function start()
P1:GetPropertyChangedSignal(“CurrentPosition”):Connect(start)
P1.Speed = 4

if P1.CurrentPosition == 0 then 
	
	P2.Speed = 4




P3.Speed = 4
P4.Speed = 4

end

start()

you have to define start before connecting it to an event

local P1 = script.Parent.P1
local P2 = script.Parent.P2
local P3 = script.Parent.P3
local P4 = script.Parent.P4

function start()
    P1.Speed = 4
    if P1.CurrentPosition == 0 then 	
        P2.Speed = 4
        P3.Speed = 4
        P4.Speed = 4
    end
end

P1:GetPropertyChangedSignal(“CurrentPosition”):Connect(start)

P1:GetPropertyChangedSignal(“CurrentPosition”):Connect(start)
it shows the " right before CurrentPosition as a error says expected a identifier got ?

sorry for some reason discourse (the service the devforum uses) changed the quotation marks to another unicode character, just change the quotation marks to actual quotation marks and you should be fine

hmm now nothing moves but i get no error. weird.

GetPropertyChangedSignal tends not to fire for properties set by physics. It will only fire if the property is set explicitly by scripts. It should be on a Stepped loop instead, since the property is expected to change (even if only every so slightly) every frame.

2 Likes