How to make a Player stick on a Moving Part

Hey there all,
I’ve been making this Spinning Part but when I stand on it the player slides right off the platform.

Video Footage

And Here is my Code:

local function SpinPart(speed: number, part: Part)
	-- || Tween For Spinning Parts
	local PartSpinInfo = TweenInfo.new(
		speed, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, -1, false
	)
	local SpinTween = TweenService:Create(part, PartSpinInfo, {CFrame = part.CFrame * CFrame.Angles(0, math.rad(180), 0)})	
	SpinTween:Play()
	
end

It is just a tween that makes the part spin forever,
thanks a lot!

I guess you could use AlignOrientation and AlignPosition in conjunction on the player (is that the right word?) or you could align the player’s CFrame with the part (when you’ve detected that they’re on the part either using a raycast or by using a touched event)

1 Like

I don’t know how to scirpt it into my part code though

1 Like

Doing this can be extremely complicated. And easier way to achieve the same effect is by using AlignPosition and AlignOrientation at maximum responsiveness. Set the two at One Attachment mode and then set the position you like and then using tweenservice rotate the CFrame of the AlignOrientation and this will also allow the character to rotate.

3 Likes

I was cooking up a response but it’s a bit inefficient. Maybe it would be like a Touched event + checking if the part is spinning or raycasting every (x) seconds and checking if the part is spinning

(both aren’t very performant either way when done frequently)

1 Like

Oh wait I’m dumb I have a better idea, just tag all of the parts that are spinning and then you just check for a Touched event for those parts

And then you’d check if it’s a character, and then you’d constantly rotate it and align it then

1 Like

wait im not sure how to do that though, by likek taggin the parts

1 Like

Just go to the parts’ Properties (in the properties tab) and just scroll down all the way to the bottom.

It should be above “attributes”

you can then just create a tag (make sure when you do it for all the parts, you use the same tag)

And when you wanna get that tag you can use CollectionService

1 Like

ooh yep I see it, what do I do after

1 Like

I’ll give you a basic example of what I mean

local TagName = "tag name"
local Parts = CollectionService:GetTagged(TagName)

local function activateAlign(otherPart, part)
   if otherPart.Parent:IsA("Model") and otherPart.Parent:FindFirstChild("Humanoid") then
      otherPart.Parent.HumanoidRootPart.CFrame = part.CFrame
   end
end

for i, part in pairs(Parts) do
   Part.Touched:Connect(function(otherPart)
         activateAlign(otherPart, Part)
   end)
end

Now this probably won’t work, Im just giving you a layout on how it would look. Just kinda something to keep in mind

ya just replace “tag name” with the name of your tag

you could also just add a AlignOrientation and AlignPosition when the player touches the spinning parts and then destroy the Aligners once the player stops making contact if that makes sense

1 Like

Alright thanks for the help, btw how would I code AlignOrientation and AlignPosition into my script?

1 Like

You’d just use Instance.new like uh this

local AlignPos = Instance.new("AlignPosition")
local AlignRot = Instance.new("AlignOrientation")
AlignPos.Parent, AlignRot.Parent = otherPart.Parent.HuannoidRootPart, otherPart.Parent.HumanoidRootPart

Just mess with the settings of each instance until you get something good. And make sure to look at the docs here:

AlignPosition - Docs
AlignOrientation - Docs

2 Likes

That’s a whole lot of work for something really simple.
Tweening a rotating part doesn’t make sense to me.
Just use a HingeConstraint set to Motor on the unanchored spinning Part. No scripting involved.

Constraints are physics based, so players will move on them.

The other thing to do when using tweens is to tween an anchored Part, but make it cancollide false and weld an unanchored Part to the anchored one. The tweened part is CFramed, so it causes the slipping issue, but when you weld an unanchored Part to it then the unanchored Part spins physically and the player can move with it.

3 Likes