Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Changing a block's velocity via a script?

Asked by 6 years ago

I was using CFrame to move a block back and forth, but need a way for it to also move the player. I tried using velocity, and it worked, but I couldn't seem to figure out how to code it into the script (as the block moves back and forth). Could someone help me with this?

Here's the code I currently have:

local brick=script.Parent
while wait(0.5) do
for I=1,50 do
brick.CFrame=brick.CFrame+Vector3.new(0.5,0,0)
wait()
end
wait(0.5)
for I=1,50 do
brick.CFrame=brick.CFrame+Vector3.new(-0.5,0,0)
wait()
end
end
0
you could use body position and body velocity instead of cframe deerdharok 91 — 6y
0
The reason I'm using CFrame is because it just glides along at one speed. I don't want it to slow down. Ender_Derp -3 — 6y

3 answers

Log in to vote
0
Answered by 6 years ago

The only thing that you did wrong is forget to put CFrame.new in front of the value you want to change it to. Adding it would make your script look like this:

local brick=script.Parent
while wait(0.5) do
for I=1,50 do
brick.CFrame=CFrame.new(brick.CFrame+Vector3.new(0.5,0,0))
wait()
end
wait(0.5)
for I=1,50 do
brick.CFrame=CFrame.new(brick.CFrame+Vector3.new(-0.5,0,0))
wait()
end
end
0
Using your code, the block now doesn't move at all Ender_Derp -3 — 6y
0
hm cmgtotalyawesome 1418 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

Okay. I don't know if I explained this correctly before. I have a platform moving with CFrame. I need it to also move the player. Editing the Velocity value in a brick will turn it into a conveyor belt, which I figured would work. The brick moves just fine. I need to know how to change the Velocity value of the brick via the script so when the brick moves forward, the player moves forward, and vice versa.

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

ive modified your script so the player moves alongisde the part,

local brick=script.Parent

while wait(0.5) do
    brick.Velocity = Vector3.new(15,0,0)
for I=1,50 do

brick.CFrame=brick.CFrame+Vector3.new(0.5,0,0)

wait()
end
brick.Velocity = Vector3.new(0,0,0)
wait(0.5)
brick.Velocity = Vector3.new(-15,0,0)
for I=1,50 do
brick.CFrame=brick.CFrame+Vector3.new(-0.5,0,0)
wait()

end
brick.Velocity = Vector3.new(0,0,0)
end

however i still strongly suggest you use body movers

this is the code for a 6x1x6 part,

BodyGyro; maxtorque = 400000, 400000, 400000 p=10000

BodyPosiiton mastorque = 100000, 100000, 100000 p = 5000 positon = (varies)

script;

local model     = script.Parent 
local platform      = model.Platform
local bodyPos       = platform.BodyPosition
local pos1          = platform.Position 
local pos2          = (platform.CFrame*CFrame.new(14,0,0)).p 
local waitTime      = 2 

bodyPos.position    = pos1
platform.Anchored   = false

local currentPos    = pos1
while wait(waitTime) do
    if currentPos == pos1 then
        currentPos          = pos2
        bodyPos.position    = pos2
    elseif currentPos == pos2 then
        currentPos          = pos1
        bodyPos.position    = pos1
    end
end
0
oh and the part for cframe needs to be anchored, or else the velocity will reset itself deerdharok 91 — 6y

Answer this question