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

Help with CFraming a whole model?

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)

1 comment

0

Why is the WoodWall in Lighting?

1 answer

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.

4 comments

0

All you did was remove the comments. Didn't help OP at all's

0

I sure did change the CFraming. From: woodwall:SetPrimaryPartCFrame(CFrame.new(game.Players.LocalPlayer.Character.Torso.CFrame.p)) wait(.01) woodwall:SetPrimaryPartCFrame(curframe * CFrame.Angles(0, math.rad(90), 0)), to: woodwall:SetPrimaryPartCFrame(cf + (lvoffset.Z + rvoffset.X + offset.Y))

0

Workspace.Voy1980.ClassicSword.LocalScript:19: bad argument #2 to '?' (Vector3 expected, got number)

0

I see the error, sorry my mistake. Replace: woodwall:SetPrimaryPartCFrame(cf + (lvoffset.Z + rvoffset.X + offset.Y)), with woodwall:SetPrimaryPartCFrame(cf + (lvoffset.Z + rvoffset.X + Vector3.new(0,offset.Y,0)))

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