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

(FIXED) Help with model orientation when summon, please, what i did wrong?

Asked by 5 years ago
Edited 5 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")


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)

1 answer

Log in to vote
1
Answered by
Bertox 159
5 years ago
Edited 5 years ago

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
0
what is "Model" and "Part"? darkzerobits 92 — 5y
0
Model is your Skateboard and Part is the Torso, You'll have to change that, it is just an example Bertox 159 — 5y
0
If this worked, I'd really love if you gave me a thumbs up and accept my answer Bertox 159 — 5y
0
isn't working :( darkzerobits 92 — 5y
View all comments (3 more)
0
i think the error is how i have set the torso darkzerobits 92 — 5y
0
still not working '-' darkzerobits 92 — 5y
0
now it worked, i used "root.Test:SetPrimaryPartCFrame(Torso.CFrame + Torso.CFrame.lookVector*10)" darkzerobits 92 — 5y
Ad

Answer this question