I'm trying to make a script that will clone a model from lighting and teleport it directly in front of where your player is facing, basically a building system activated by a tool. Problem is, I can't figure out how to cframe an entire model while offsetting it to bring it in front of the player. The furthest I've gotten is directly teleporting the model to the player using SetPrimaryPartCFrame, but that doesn't help with the offset or rotation due to it expecting a Vector3 value. I'm new to scripting and this is what I have written, which is terrible. It may also be jumbled because I kept trying new things. Thank you for any help.
local Tool = script.Parent local Debris = game:GetService("Debris") local offset = CFrame.new(0, 0, 10) local root = game.Players.LocalPlayer.Character.Torso Tool.Equipped:Connect(function(mouse) Tool.Activated:Connect(function(mouse) local woodwall = game.Lighting.WoodWall:Clone() print("Cloned From Lighting") woodwall.Parent = game.Workspace --woodwall:SetPrimaryPartCFrame(woodwall.Center) woodwall.PrimaryPart = woodwall.Center Debris:AddItem(woodwall, 10) local curframe = woodwall.Center.CFrame local pos = game.Players.LocalPlayer.Character.Torso.CFrame.p local lv = game.Players.LocalPlayer.Character.Torso.CFrame.LookVector woodwall:SetPrimaryPartCFrame(CFrame.new(game.Players.LocalPlayer.Character.Torso.CFrame.p)) wait(.01) woodwall:SetPrimaryPartCFrame(curframe * CFrame.Angles(0, math.rad(90), 0)) --woodwall:SetPrimaryPartCFrame(CFrame.new(game.Players.LocalPlayer.Character.Torso.CFrame.p)) --woodwall:MoveTo(game.Players.LocalPlayer.Character.Torso.CFrame.p)--*Vector3.new(offset), + offset print("CFramed") end) end)
This should work for you.
local Tool = script.Parent local Debris = game:GetService("Debris") local offset = Vector.new(0, 0, 10) local root = game.Players.LocalPlayer.Character.Torso Tool.Equipped:Connect(function(mouse) Tool.Activated:Connect(function(mouse) local woodwall = game.Lighting.WoodWall:Clone() print("Cloned From Lighting") woodwall.Parent = game.Workspace woodwall.PrimaryPart = woodwall.Center Debris:AddItem(woodwall, 10) local curframe = woodwall.Center.CFrame local cf = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame local lv = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame.LookVector local rf = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame.RightVector woodwall:SetPrimaryPartCFrame(cf + (lv*offset.Z + rv*offset.X + Vector3.new(0,offset.Y,0))) end) end)
If you are getting errors message me.