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

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

Asked by 6 years ago

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

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? Bellyrium 310 — 6y
0
I need them to both run at the same time. MisterThackeryBinx 29 — 6y

2 answers

Log in to vote
1
Answered by
Bellyrium 310 Moderation Voter
6 years ago

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


0
Yea, I only just learned about Coroutines today xD PolyyDev 214 — 6y
Ad
Log in to vote
2
Answered by
PolyyDev 214 Moderation Voter
6 years ago

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
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! Bellyrium 310 — 6y

Answer this question