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

How do i make the cframe keep increasing from its original position?

Asked by 2 years ago
Edited 2 years ago

Hi! I have a script which "extends" a corridor by cloning itself and placing it on the end of the previous one. However, currently, it just pastes the corridor infront of the previous and stacks. Anyone have any ideas? Script:

while true do
    local infgen = game.Workspace:FindFirstChild("original"):Clone()
    local pos = infgen.PrimaryPart.CFrame * CFrame.new(0, 0, 334.464) 
    wait(12)
    infgen.Name = "notorig"
    infgen:SetPrimaryPartCFrame(pos)
    wait(.4)
        infgen.Parent = game.Workspace
end

2 answers

Log in to vote
1
Answered by
ShaShxa 105
2 years ago

Hey!

The mistake you are doing is you are always grabbing the CFrame from the original corridor, instead grabbing it from the latest created corridor.

I think this should fix it if I am not mistaken:

local AmountOfCorridors = 0 -- Add variable to define how much corridors you have cloned.

while true do
    local infgen = game.Workspace:FindFirstChild("original"):Clone()
    infgen.Name = "notorig"..AmountOfCorridors -- Creating the model, always having a number behind it (notorig1, notorig2, notorig3, and so on...)

    local pos = game:Workspace:FindFirstChild("notorig"..AmountOfCorridors).PrimaryPart.CFrame * CFrame.new(0, 0, 334.464) -- Find the latest created corridor 

    wait(.1)

    AmountOfCorridors = AmountOfCorridors+1 -- Adding +1 because we have created a new corridor.
    infgen:SetPrimaryPartCFrame(pos)
    wait(12)
end

Let me know if this worked!

0
mhm you got it faster than me, good job SuperPuiu 497 — 2y
0
I did think i had to do something like this but wasn't sure how to get around doing it, Thank you! Mrpolarbear2games 55 — 2y
Ad
Log in to vote
1
Answered by
SuperPuiu 497 Moderation Voter
2 years ago
Edited 2 years ago

The code might not work, Im on mobile :p rename "original" model from workspace to "original0"

local nr = 0
while true do 
nr = nr + 1
local infgen= game.Workspace:FindFirstChild("original"..nr):Clone() 
local pos = infgen.PrimaryPart.CFrame * CFrame.new(0, 0, 334.464) 
wait(12) 
infgen.Name = "original" ..nr
infgen:SetPrimaryPartCFrame(pos) 
wait(.4)
 infgen.Parent = game.Workspace end

Edit: it was alr answered

0
Thanks, This is amazing! Keep up the great work! :) Mrpolarbear2games 55 — 2y

Answer this question