So when i place an object down with my placement system i created then if i rotate it it dosen't save when it places down like if you press R and it rotates then when the preview is showing that it is rotated then when i place it down it dosen't save the rotation as it was in the preview why?

Heres the script:

repeat wait()
	player = game.Players.LocalPlayer;
	character = player.Character;
until (player) and (character)

local resources = game.ReplicatedStorage:WaitForChild("Resources");
	local models, remotes = resources:WaitForChild("Models"), resources:WaitForChild("Remotes");
	local chosenModel
	
local camera, mouse = game.Workspace.CurrentCamera, player:GetMouse();

local create = function(instance, properties)
	for i,v in pairs(properties) do
		instance[i] = v;
	end;
	return instance;
end;

local movingmodel = nil;

local grid_snap = function(model, grid, index)
	
		movingmodel = model;
		
		mouse.TargetFilter = game.Workspace:WaitForChild("Container");
		
		local x, y = math.floor(mouse.Hit.X), math.floor(mouse.Hit.Z);
			local mouseposition = Vector3.new(x, grid.Position.Y, y);
			
			local magnitude, nearpoint = math.huge, nil;
			
			for _,v in pairs(settings.gridindex) do
				for i,z in pairs(v) do
					
					local position = z.position;
						local pointmagn = (position.p - mouseposition).magnitude;
						if (pointmagn < magnitude) then
							nearpoint, magnitude = z, pointmagn;
						end;
				end;
			end;
			
			if (movingmodel) then
				if (nearpoint.occupied) then
					model.Hitbox.SelectionBox.Color3 = Color3.new(1, 48/255, 51/255);
						edit_properties(model, {Color = Color3.new(1, 48/255, 51/255), Transparency = 1;});
						edit_properties(model, {CanCollide = false;});
				else
					model.Hitbox.SelectionBox.Color3 = Color3.new(67/255, 142/255, 82/255);
					edit_properties(model, {Color = Color3.new(67/255, 142/255, 82/255), Transparency = .4;});
					edit_properties(model, {CanCollide = false;});
				end;
			end;
			
			settings.hitspot = nearpoint;			
			
			model:SetPrimaryPartCFrame((CFrame.new(0, 0.2, 0) + nearpoint.position.p) * CFrame.Angles(0, math.rad(model.PrimaryPart.Orientation.Y), 0));
end;

local setup_index = function(grid, index)
	
	local x, y = grid.Size.X, grid.Size.Z;
		local xlength, ylength = math.floor(x / settings.gridsize), math.floor(y / settings.gridsize);
		
	for xindex = 1, xlength do
		
		index[xindex] = {};
		
		for yindex = 1, ylength do
			
			index[xindex][yindex] = {
				occupied 	= false;
				position	= CFrame.new(-((xindex - 1) * 4) + ((x / 2) - (settings.gridsize / 2)), 0,
										 -((yindex - 1) * 4) + ((y / 2) - (settings.gridsize / 2))) + grid.Position;			
				indexitem   = nil;
				};
		end;
	end;
	
	
	
end;
			
		
local grid = function(base)
	local x, y = base.Size.X, base.Size.Z;
		local xlength, ylength = math.floor(x / settings.gridsize), math.floor(y / settings.gridsize);
		
		local folder = camera:FindFirstChild("GridIndex");
		if (folder) then folder:Destroy(); end;
		
		folder = create(Instance.new("Folder"), {
				Name 	= "GridIndex";
				Parent	= camera;
			
		});
		
local tweenInfo = TweenInfo.new(
	.4,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.In,
	0,
	false,
	0
);
		
		for i = 1,(xlength + 1) do
			
			local line = create(Instance.new("LineHandleAdornment"), {
					SizeRelativeOffset	= Vector3.new(1 - (((i - 2) * 2) / xlength), 0, 1) + settings.gridoffset;
					Color3				= Color3.new(1,1,1);
					Length				= y;
					Thickness			= settings.gridthickness;
					Adornee				= base;
					Parent				= folder;
			});
			
			local tween = game:GetService("TweenService"):Create(line, tweenInfo, {Length = y});
				tween:Play();
			
			end;
		
			for v = 1,(ylength + 1) do
			
				local line = create(Instance.new("LineHandleAdornment"), {
						CFrame				= CFrame.new(0, 0, 0) * CFrame.Angles(0, math.rad(90), 0);
						SizeRelativeOffset	= Vector3.new(1, 0, 1 - (((v - 1) * 2) / ylength)) + settings.gridoffset;
						Color3				= Color3.new(1,1,1);
						Length				= x;
						Thickness			= settings.gridthickness;
						Adornee				= base;
						Parent				= folder;
				});
				
				local tween = game:GetService("TweenService"):Create(line, tweenInfo, {Length = x});
					tween:Play();
			
				end;
				

end;

local insert_model = function(model)
	
	previewmodel, placed = game.ReplicatedStorage.Resources.Models[chosenModel].Model:Clone(), false;
		previewmodel.Parent = workspace.Container
			previewmodel.Base.Transparency = 0;
			local SelectionBox = Instance.new("SelectionBox", previewmodel.Hitbox)
			SelectionBox.Name = "SelectionBox"
			SelectionBox.LineThickness = 0.1
			SelectionBox.Adornee = previewmodel.Hitbox		
	mouse.Button1Down:connect(function()
		if (not settings.hitspot.occupied) then
			placed = true;
		end;
	end);
	
	repeat wait()
		grid_snap(previewmodel, settings.grid, settings.gridindex)
	until (placed)
	
	local folder = camera:FindFirstChild("GridIndex");
		if (folder) then folder:Destroy(); end;
		
	 local placedmodel = game.ReplicatedStorage.Resources.Models[chosenModel].Model:Clone();
		placedmodel.Parent = game.Workspace["Container"];
		
		placedmodel:SetPrimaryPartCFrame((CFrame.new(0, 0.2, 0) + settings.hitspot.position.p) * CFrame.Angles(0, math.rad(placedmodel.PrimaryPart.Orientation.Y), 0));
		
	previewmodel:Destroy()
		
	movingmodel = nil;
	
	settings.hitspot.occupied = true;
end;

local open = false
script.Parent.UI.Frame.ConstructButton.MouseButton1Click:connect(function()
	if not (open) then
		script.Parent.UI.Construct.Visible = true
		open = true
	else
		script.Parent.UI.Construct.Visible = false
		open = false
	end
end)

script.Parent.UI.Frame.RemoveButton.MouseButton1Click:connect(function()
	--if not placed then
		for _,v in pairs(workspace.Container:GetChildren()) do
			v.Arcade.MouseButton1Click:connect(function()
				v.Parent:Destroy()
			end)
		end
	--end
end)

for _,v in pairs(script.Parent.UI.Construct:GetChildren()) do
	if movingmodel == nil then
		v.MouseButton1Click:connect(function()
			script.Parent.UI.Construct.Visible = false
			open = false
			grid(settings.grid);
			chosenModel = v.Name
			insert_model(models[chosenModel].Model)
		end)
	end
end

game:GetService("UserInputService").InputBegan:connect(function(input)
	
				if (input.KeyCode == Enum.KeyCode.R) and (movingmodel ~= nil) then
					h = movingmodel:SetPrimaryPartCFrame(movingmodel.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(90), 0));
				elseif (input.KeyCode == Enum.KeyCode.G) and (movingmodel == nil) then
					
					grid(settings.grid);
					
					insert_model(models[chosenModel].Model)
				end;
	end);

setup_index(settings.grid, settings.gridindex);	

2 comments

0

Please be more clear in your question.

0

when you rotated it when you are placing it down and then when you click to place it down the rotation isnt as the preview before you placed it