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

Help with CFraming a whole model?

Asked by 5 years ago

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)

0
Why is the WoodWall in Lighting? User#19524 175 — 5y

1 answer

Log in to vote
-1
Answered by
jaschutte 324 Moderation Voter
5 years ago
Edited 5 years ago

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.

0
All you did was remove the comments. Didn't help OP at all's User#19524 175 — 5y
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 + (lv*offset.Z + rv*offset.X + offset.Y)) jaschutte 324 — 5y
0
Workspace.Voy1980.ClassicSword.LocalScript:19: bad argument #2 to '?' (Vector3 expected, got number) awad6314 9 — 5y
0
I see the error, sorry my mistake. Replace: woodwall:SetPrimaryPartCFrame(cf + (lv*offset.Z + rv*offset.X + offset.Y)), with woodwall:SetPrimaryPartCFrame(cf + (lv*offset.Z + rv*offset.X + Vector3.new(0,offset.Y,0))) jaschutte 324 — 5y
Ad

Answer this question