(FIXED) Help with model orientation when summon, please, what i did wrong?
Asked by
6 years ago Edited 6 years ago
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")
01 | local skateboardId = 2064283039 |
02 | local Tool = script.Parent; |
08 | local root = game:GetService( "InsertService" ):LoadAsset(skateboardId) |
11 | local instances = root:GetChildren() |
12 | if #instances = = 0 then |
18 | root.Name = "InsertedObject" .. skateboardId |
20 | game:GetService( "InsertService" ):Insert(root) |
22 | local t = game.Players.LocalPlayer.Character:FindFirstChild( "Torso" ) |
23 | root:MoveTo(t.Position + t.CFrame.lookVector * 8 ) |
24 | root.Test.PartePrimaria:SetPrimaryPartCFrame(CFrame.LookVector) |
27 | Tool.Handle.Drop:Play() |
34 | function onButton 1 Down(mouse) |
50 | function onEquippedLocal(mouse) |
53 | print ( "Mouse not found" ) |
57 | mouse.Button 1 Down:connect( function () onButton 1 Down(mouse) end ) |
61 | Tool.Equipped:connect(onEquippedLocal) |
Working script :
01 | local skateboardId = 2064283039 |
02 | local Tool = script.Parent; |
03 | local Player = game:GetService( 'Players' ).LocalPlayer |
04 | local Character = Player .Character or Player.CharacterAdded:Wait() |
05 | local Torso = Character.Torso |
10 | local root = game:GetService( "InsertService" ):LoadAsset(skateboardId) |
13 | local instances = root:GetChildren() |
14 | if #instances = = 0 then |
20 | root.Name = script.Parent.Parent.Name |
22 | game:GetService( "InsertService" ):Insert(root) |
24 | local t = game.Players.LocalPlayer.Character:FindFirstChild( "Torso" ) |
25 | root:MoveTo(t.Position + t.CFrame.lookVector * 8 ) |
26 | root.Test:SetPrimaryPartCFrame(Torso.CFrame + Torso.CFrame.lookVector* 10 ) |
29 | Tool.Handle.Drop:Play() |
36 | function onButton 1 Down(mouse) |
52 | function onEquippedLocal(mouse) |
55 | print ( "Mouse not found" ) |
59 | mouse.Button 1 Down:connect( function () onButton 1 Down(mouse) end ) |
63 | Tool.Equipped:connect(onEquippedLocal) |