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

How to reset model's position?

Hey, I have this script that makes a few jets spawn and fly above your head and then despawn. However, I have an issue. I need to reset the position of the model so the command can be reused. I tried copying and editing the while loop part so it would reverse the whole thing but it ended up too far from its actual original position. Can't destroy the model and clone it back again as that would give me the parent property is locked error. Anyone know how to?

local model = game:GetService("ServerStorage").Flight
local copy = model:Clone()

game:GetService("Players").PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		if string.lower(msg) == "/e flight" then
			copy.Parent = workspace
			script.Value.Value = true
			wait()
			while script.Value.Value == true do
				for i = 1,100 do
					wait()
					copy:SetPrimaryPartCFrame(CFrame.new(copy.PrimaryPart.Position + Vector3.new(0,0,-20)))
				end
			end
			copy.Parent = game:GetService("ServerStorage")
		end
	end)
end)

1 answer

✓ Accepted answer

Make a variable for it's starting CFrame, that way you can set it back once the command is done

if string.lower(msg) == "/e flight" then
    copy.Parent = workspace
    script.Value.Value = true
    local StartCFrame = Copy.PrimaryPart.CFrame
    wait()
    while script.Value.Value == true do
        for i = 1,100 do
            wait()
            copy:SetPrimaryPartCFrame(CFrame.new(copy.PrimaryPart.Position + Vector3.new(0,0,-20)))
        end
    end
    copy.Parent = game:GetService("ServerStorage")
    copy:SetPrimaryPartCFrame(StartCFrame)
end

Honestly if I were you I would just clone it in the command and then destroy it, instead of reusing one model.

2 comments

0

Cloning it in the command is a good idea, I have no clue why didn't I think of that before, I'm gonna try.

0

Yep it worked. Thanks.

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