Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help with a cframe script? Want it to run and then do rest of script.

Hello,

So I have a script here and as you can see I have some cframe in it. Right now, it's doing two diffrent Cframes. How it's working is it's moving one, waiting for it to finish and then move on to the next line. I want it so that it does not wait to for the first cframe to finish and just go to the second. Thanks, Anthony

local Epic=script.Parent.ClickDetector
function onClick()
for i = 0, 17.5, 0.2 do
game.Workspace.Kitchen:SetPrimaryPartCFrame(game.Workspace.Kitchen:GetPrimaryPartCFrame() + Vector3.new(0.2,0,0))
wait()
end
for i = 0, 10, 0.2 do
game.Workspace.Lights:SetPrimaryPartCFrame(game.Workspace.Lights:GetPrimaryPartCFrame() + Vector3.new(0,.8,0))
wait()
end

2 comments

0

I am unsure what you mean.. Do you want the first loop to switch over to the next loop faster? Or would you like it to move over then up repeated?

0

I need them to both run at the same time.

2 answers

✓ Accepted answer

Ok, so I would recommend you use Lerp(). Ill give you an example I think should help!

Start:Lerp(End,increment) returns a position between Start and End. Increment is between 0-1 so increment of 0.5 would be halfway, 1 would be the end, 0 would be the start.

local Epic=script.Parent.ClickDetector
function onClick()
local StartPos = game.Workspace.Kitchen.PrimaryPart.CFrame
local EndPos = StartPos + Vector3.new(35,16,0)
for i = 0,1, 0.1 do wait()
	game.Workspace.Kitchen:SetPrimartPartCFrame(StartPos:lerp(EndPos, i) 
end
end


1 comment

0

Yea, I only just learned about Coroutines today xD

Use a spawn function. It makes the function that you "spawned" run in a then moves on to the then moves on to the next line instantly after. So you will need something like:

local Epic=script.Parent.ClickDetector
function onClick()
for i = 0, 17.5, 0.2 do
game.Workspace.Kitchen:SetPrimaryPartCFrame(game.Workspace.Kitchen:GetPrimaryPartCFrame() + Vector3.new(0.2,0,0))
wait()
end
spawn(onClick) -- Im not sure if thats right if its now just search it on youtube
for i = 0, 10, 0.2 do
game.Workspace.Lights:SetPrimaryPartCFrame(game.Workspace.Lights:GetPrimaryPartCFrame() + Vector3.new(0,.8,0))
wait()
end

1 comment

1

spawn is handy, but its recommended you learn to use the thread scheduler too! Coroutines are more generally more powerful then spawned functions. This should work though!

This discussion is preserved as it was. New answers, comments, and votes are closed.