Im not very good using Cframe and Vector3, but i tried, this script "spawn" a model in front of me, and rotate the model to where im looking, but it doesn't work, the script spawn the model, but dont rotate it, what i did wrong?
(Its a LocalScript, in a Tool / The name of the model is test, and i already set the PrimaryPart, that is the "PartePrimaria")
local skateboardId = 2064283039 local Tool = script.Parent; function insert() --This call will cause a "wait" until the data comes back local root = game:GetService("InsertService"):LoadAsset(skateboardId) local instances = root:GetChildren() if #instances == 0 then root:Remove() return end --Continue the insert process root.Name = "InsertedObject" .. skateboardId game:GetService("InsertService"):Insert(root) local t = game.Players.LocalPlayer.Character:FindFirstChild("Torso") root:MoveTo(t.Position + t.CFrame.lookVector * 8) root.Test.PartePrimaria:SetPrimaryPartCFrame(CFrame.LookVector) Tool.Handle.Drop:Play() end enabled = true function onButton1Down(mouse) if not enabled then return end enabled = false insert() wait(.01) Tool:Remove() end function onEquippedLocal(mouse) if mouse == nil then print("Mouse not found") return end mouse.Button1Down:connect(function() onButton1Down(mouse) end) end Tool.Equipped:connect(onEquippedLocal)
Working script :
local skateboardId = 2064283039 local Tool = script.Parent; local Player = game:GetService('Players').LocalPlayer local Character = Player .Character or Player.CharacterAdded:Wait() local Torso = Character.Torso --<< this is Torso function insert() --This call will cause a "wait" until the data comes back local root = game:GetService("InsertService"):LoadAsset(skateboardId) local instances = root:GetChildren() if #instances == 0 then root:Remove() return end --Continue the insert process root.Name = script.Parent.Parent.Name game:GetService("InsertService"):Insert(root) local t = game.Players.LocalPlayer.Character:FindFirstChild("Torso") root:MoveTo(t.Position + t.CFrame.lookVector * 8) root.Test:SetPrimaryPartCFrame(Torso.CFrame + Torso.CFrame.lookVector*10) Tool.Handle.Drop:Play() end enabled = true function onButton1Down(mouse) if not enabled then return end enabled = false insert() wait(.01) Tool:Remove() end function onEquippedLocal(mouse) if mouse == nil then print("Mouse not found") return end mouse.Button1Down:connect(function() onButton1Down(mouse) end) end Tool.Equipped:connect(onEquippedLocal)
You have to set CFrame for lookVector:
root.Test:SetPrimaryPartCFrame(Torso.CFrame + Torso.CFrame.lookVector*10)
You are using .MouseButton1Down, so it reacts, even when your Tool is not equipped. So you can use .Activated , it only fires when the tool is equipped and you click.
function activated() -- end Tool.Activated:connect(activated)
To get the Torso properly in a local script, you do this:
local Player = game:GetService('Players').LocalPlayer local Character = Player .Character or Player.CharacterAdded:Wait() local Torso = Character.Torso --<< this is Torso