Whenever I attempt to change the Rotation of am Part using the 'onTouched' function, it floats above my Players head. My script I use:
There is a script inside of the Part I have been testing.
Part = script.Parent
Part.Anchored = true
Part.Rotation = Vector3.new(0,0,0)
Part.Position = Vector3.new(-6.5,1.1,7)
function onTouched() Part.Rotation = Vector3.new(0,89.98,0) wait(2) Part.Rotation = Vector3.new(0,0,0) end Part.Touched:connect(onTouched)
You really should put your code in a code block and tab it correctly, as it makes it much easier to read. Since this is so short, however, I can still be of help.
CFrame, in Roblox, ignores other bricks. Therefore you can use CFrame.Angles
to rotate a brick while ignoring other bricks.
You should also add a debounce to help prevent glitching. A debounce is just a variable that prevents the code from running a second time until it's already finished running the first time. This is very useful for Touched events, because the way they work they may fire a bunch of times if the person remains standing on the brick.
Also the first few lines outside the function are kind of unnecessary, as you can just make those edits in studio.
local part = script.Parent --It's normally considered best to make variables lower case, your choice though. You should make them local, however, since it increases readability and efficiency. local debounce = false function onTouched() if not debounce then debounce = true --Prevents the code from running part.CFrame = CFrame.Angles(0,math.rad( 89.98), 0) wait(2) part.CFrame = CFrame.Angles(0, 0, 0) debounce = false --Lets the code run again. end end