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

How do I make a model with a primary part face another part?

I am trying to make a turret that has a model as its parent rotate towards the direction of the nearest player within 50 studs. Currently I am using a cylinder as the range since my scripting isn't advanced. Here is my current script:

tuching = false

script.Parent.Touched:connect(function(part)
	if part.Name ~= 'Baseplate' and part.Name ~= 'Part' then
		print('touched')
		tuching = true
		wait()
		script.Parent.Parent:SetPrimaryPartCFrame(CFrame.new(script.Parent.Parent.base.CFrame.p, Vector3.new(0,0,part.CFrame.Z)))
	end
end)

script.Parent.TouchEnded:connect(function(part)
	if part.Name ~= 'Baseplate' and part.Name ~= 'Part' then
		print('no more tuch')
		tuching = false
	end
end)

I am looking for a proper :SetPrimaryPartCFrame() method of facing towards a part with it looking up and down a.k.a without the Y axis.

1 answer

There is a way of doing this with :SetPrimaryPartCFrame()! In the second parameter of CFrame.new(), you are able to set where the part will face. Since your model has a primary part, this will make all the parts in the model face the same direction.

local part = Instance.new("Part", workspace) -- Create a part

part.CFrame = CFrame.new(Vector3.new(0, 50, 0), Vector3.new(0, 0, 0)) -- Move part 50 studs up from the origin and make it face towards the origin.

You can achieve the same thing in a model with a primary part by doing:

model:SetPrimaryPartCFrame(CFrame.new(Vector3.new(0, 50, 0), Vector3.new(0, 0, 0))

3 comments

0

Sorry if I didn't completely answer your question, but with what I have said I think you will be able to figure out the rest ;)

0

Thank you but I am trying to make it ignore the Y value to prevent it from going up and down and only look from left to right

0

No problem, if this is what you were looking for, please accept/upvote my answer :)

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