Hello, I am a complete beginner scripter and was just experimenting around with making a moving part. I want the part to move 10 studs to the right, then 10 studs to the left, then stop. Could you tell me why this is not working?
I never use Position but it should be something like this when you use CFrame: part.CFrame = CFrame + Vector3.new(0,2,0)
You aren’t using CFrame properly, I’d fix it something like this: part.CFrame = CFrame + Vector3.new(0.1,2,0)
What is X? I’m pretty sure that’s not a property.
You are not being specific on what you want to change. Replace CFrame.new(0,0,0) with part.CFrame = CFrame.new(0,2,0) 2 because that’s the height of the part.
The same with the rest of the code.
Therefore, I will use TweenService for smoother movement than CFrame.
local part = Instance.new("Part") -- Create part
part.Parent = workspace
part.Anchored = true
part.CanCollide = true
part.CFrame = CFrame.new(0,5,0) -- Spawn Position.
wait(10) -- A wait function so it gives you time to load.
local tweenService = game:GetService('TweenService') -- Get TweenService.
local tweenInfo = TweenInfo.new(3) --Time to reach to final position.
local properties = {CFrame = CFrame.new(10,5,0)} -- The new position you want.
local tween = tweenService:Create(part, tweenInfo, properties) --Creating tween
tween:Play()
wait(1)
-- The same as the last line but makes it turn back
local tweenService = game:GetService('TweenService')
local tweenInfo = TweenInfo.new(3)
local properties = {CFrame = CFrame.new(0,5,0)}
local tween = tweenService:Create(part, tweenInfo, properties)
tween:Play()
Before pasting the entire code you should learn about CFrame for the first answer and TweenService for the fixed code.
Check it twice so you understand it. Hope it works!
Please correct me if I am wrong, as I am half new in scripting and there may be other ways to do this.