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

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

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

✓ Accepted answer

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

7 comments

0

what is "Model" and "Part"?

0

Model is your Skateboard and Part is the Torso, You'll have to change that, it is just an example

0

If this worked, I'd really love if you gave me a thumbs up and accept my answer

0

isn't working :(

0

i think the error is how i have set the torso

0

still not working '-'

0

now it worked, i used "root.Test:SetPrimaryPartCFrame(Torso.CFrame + Torso.CFrame.lookVector*10)"

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