How do I make players "stick" to a part?

I’m not sure if it’s really making them “stick” to a part, and I’m not really sure how to explain it, so I’ll show you.

This is what I want:

This is what I have:

The code I’m using to rotate the cube is:

-- Services
local runService = game:GetService('RunService')

-- Variables
local rad = math.rad
local clock = os.clock
local noise = math.noise
local random = math.random

local cube = workspace:WaitForChild('Cube')
local xSeed = random(10000, 100000)
local ySeed = random(10000, 100000)
local zSeed = random(10000, 100000)

-- CubeSpin
runService.Heartbeat:Connect(function()
	local timeFactor = clock() % 1000 * 0.1
	local x = noise(xSeed, timeFactor) * 360
	local y = noise(ySeed, timeFactor) * 360
	local z = noise(zSeed, timeFactor) * 360
	cube.CFrame = CFrame.new(cube.Position) * CFrame.Angles(rad(x), rad(y), rad(z))
end)

NOTE: I’m going to have multiple cubes which the players are going to be able to jump to!!

1 Like

It rotates via physical movers. You can use AlignOrientation.

If you want to use CFrames instead of body movers, you can use a local script to move the character with the part. Every frame, detect the part the character is standing on with rays, and then check the difference in the block’s CFrame from the last frame and the current one. Offset the CFrame of the character’s HumanoidRootPart by this same amount, and you’re good to go.

I did this in one of my places and it works well.

I’m still quite confused, I’ve tried playing around with alignorientation and I’m a little confused on how I would go about doing it, if you could tell me how I could use it that would be great :slight_smile:

Yeah, CFraming anything anchored a player is standing on creates issues.
I’d tween rotate a small anchored part with your other unanchored parts welded to it. Make the humanoid climbing angle (I can’t remember the Property name) fairly high so players can walk up the steep slopes.

Jailbreak train platform system? - #35 by Kord_K it might help

Sure. It would be better if you made the attachment and the movers beforehand if you’re doing this on the client.

-- Services
local runService = game:GetService('RunService')

-- Variables
local rad = math.rad
local clock = os.clock
local noise = math.noise
local random = math.random

local cube = workspace:WaitForChild('Cube')
local xSeed = random(10000, 100000)
local ySeed = random(10000, 100000)
local zSeed = random(10000, 100000)

-- create attachment for constraint movers
local attachment = Instance.new("Attachment")
attachment.Parent = cube

-- keep the cube in place
cube.Anchored = false

local alignPosition = Instance.new("AlignPosition")
alignPosition.RigidityEnabled = true
alignPosition.Mode = Enum.PositionAlignmentMode.OneAttachment
alignPosition.Attachment0 = attachment
alignPosition.Position = cube.Position
alignPosition.Parent = cube

-- AlignOrientation for physics rotation instead of cframe
local alignOrientation = Instance.new('AlignOrientation')
alignOrientation.RigidityEnabled = true
alignOrientation.Mode = Enum.OrientationAlignmentMode.OneAttachment
alignOrientation.Attachment0 = attachment
alignOrientation.Parent = cube

-- CubeSpin
runService.Heartbeat:Connect(function()
	local timeFactor = clock() % 1000 * 0.1
	local x = noise(xSeed, timeFactor) * 360
	local y = noise(ySeed, timeFactor) * 360
	local z = noise(zSeed, timeFactor) * 360
	
	-- rotate the AlignOrientation instead of the cube
	alignOrientation.CFrame = CFrame.Angles(rad(x), rad(y), rad(z))
end)
3 Likes

@metatablesnow oops replied to the wrong person, but read my reply above.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.