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

How do you make a brick change it's rotation to the same as the object that hit it?

Hi, I am getting a error, it says that rightVector can't be assigned to. Any help?

script.Parent.Parent.Touched:connect(function(h)
	script.Parent.Parent.CFrame.rightVector = h.CFrame.rightVector
end)

3 answers

✓ Accepted answer

Try this, perhaps. This should take only the rotation of part h and apply it.

script.Parent.Parent.Touched:connect(function(h)
    local hCFrameRotationOnly = h.CFrame - h.CFrame.p
    script.Parent.Parent.CFrame =
        hCFrameRotationOnly + script.Parent.Parent.CFrame.p
end)

1 comment

0

Works thanks!

RightVector is a read-only value, and thus cannot be changed. Something like this might help instead:

script.Parent.Parent.Touched:Connect(function(h)
	local pos = script.Parent.Parent.Position
	local lookAt = pos + h.CFrame.lookVector
	script.Parent.Parent.CFrame = CFrame.new(pos,lookAt)
end)

3 comments

0

I should make some clerifications, I want it to only be the X Axis.

0

Clarifications*

0

Also, doesn't work

Hey LennonLight,

The way that I am about to demonstrate before you is a pretty famous and easy way to change a part's direction that it faces. Well, I will show it to you below and explain it line by line. Better to demonstrate and explain at the same time rather than just say how to do it.

----Example----

local part = script.Parent; -- The part 
local parts_to_not_touch = { -- Dictionary with the names of the parts that it shouldn't react towards.
	["Baseplate"] = true;
}

part.Touched:Connect(function(obj) -- Declares an anonymous function connected to a Touched event.
	if not parts_to_not_touch[obj.Name] then -- If statement checking if the obj's name isn't any stored in the table, so it can prevent reactions to those parts.
		part.CFrame = CFrame.new(part.Position, obj.Position); -- Changes the CFrame by keeping the part's original position and sets the direction that the part is facing to the object that it touched.
	end -- end for the if statement
end) -- end for the function

##I hope that I helped, and have a nice day.

###Thanks,

###~~ KingLoneCat

1 comment

0

He doesn’t want to point the part to face the object that touched, but rather point the part in the same direction and have it face the same way as the object that touched.

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