script.Parent.Touched:Connect(function(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") local playerName = hit.Parent.Name if humanoid then print(playerName.." is cool!") local torso = hit.Parent.Torso local weld = Instance.new("Weld") script.Parent.CFrame = torso.CFrame * CFrame.new(0, 0, 1, 90, 0, 0) weld.Part0 = torso weld.C0 = torso.CFrame:Inverse() weld.Part1 = script.Parent weld.C1 = script.Parent.CFrame:Inverse() weld.Parent = script.Parent script.Parent.Anchored = false end end)
I understand how to do the position but for me, the thing I got confused on was the rotation of it. I attempted to add 3 numbers on to it for a rotation as I would in HTML but that didn't have any results.
instead of using Welds
use WeldConstraints
so the joint doesnt break when you try to rotate the connected parts. use CFrame.Angles()
to rotate the part. also this would only work for R6 since R15 and rthro dont have torsos, instead you could use the HumanoidRootPart which is available on all avatars.
script.Parent.Touched:Connect(function(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") local playerName = hit.Parent.Name if humanoid then print(playerName.." is cool!") local torso = hit.Parent.HumanoidRootPart local weld = Instance.new("WeldConstraint") script.Parent.CFrame = torso.CFrame * CFrame.Angles(0,math.rad(90),0) -- rotates it by 90° weld.Part0 = torso weld.Part1 = script.Parent weld.Parent = script.Parent script.Parent.Anchored = false end end)