I'm trying to make a block rotate and have any player standing on it move with the rotation of the block but no matter how I go about coding it, the block just rotates without also moving the players standing on it.
Here is the code using CFrame:
while true do script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(.002,.005,.009) wait(.001) end
Here is the code using Vector3:
platform = script.Parent a = 0 b = 0 c = 0 while true do platform.Rotation = Vector3.new(a, b, c) wait(0.01) a = a + 0.1 b = b + 0.2 c = c + 0.15 end
Any suggestions on how I can make the player rotate with the platform?
To make a player stick onto a moving part, whether that be a spinning or just translating, you should use a BodyMover.
BodyMovers are a class of instances in roblox that exert forces on baseparts. There are Seven types of BodyMovers currently in roblox BodyForce
,BodyPosition
, and BodyVelocity
for translation, BodyThrust
,BodyGyro
, and BodyAngularVelocity
for rotation, and the odd one out, RocketPropulsion
To achieve what you are trying to do, you can use the BodyGyro to maintain a constant rotation.
One thing to keep in mind is that CFrame.fromEulerAngles and CFrame.Angles uses radians instead of degrees. Generally, a degree is pi/180 radians, as a pi radians is 180 degrees
local Gyro = script.Parent.BodyGyro local ang = 0 Torque = Vector3.new(math.huge,math.huge,math.huge) Gyro.MaxTorque = d while true do Gyro.CFrame = Gyro.CFrame * CFrame.Angles(0,math.rad(ang/10),0) print(Gyro.CFrame) ang = ang + 1 wait(0.1) end
Now that you have a rotating part, you might want to make it float.
To do this, you can use a BodyPosition
.
Ex:
local BodyPos = script.Parent.BodyPosition BodyPos.MaxForce = Vector3.new(math.huge,math.huge,math.huge) BodyPos.Position = Vectore.new(x,y,z) --placeholder coordinates
Possibility 1: Using lookVectors
My first suggestion is to use lookVectors to push the player along the face they are standing on.
local player = game.Players.LocalPlayer local part = workspace.Part part.Touched:Connect(function() player.Character:SetPrimaryPartCFrame(player.Character.HumanoidRootPart.CFrame + (part.CFrame.LookVector * Vector3.new(0.05, 0, 0))) end) while true do part.CFrame = part.CFrame * CFrame.fromEulerAnglesXYZ(.002,.005,.009) wait(.001) end
Possibility 2: Using Welds
My second thought is to try Welds, which will guarantee the player is moving with the part's rotation, but must be broken / removed by another function (as the player wlll be unable to move)
local player = game.Players.LocalPlayer local part = workspace.Part part.Touched:Connect(function() local weld = Instance.new("Weld", player.Character.HumanoidRootPart) weld.Part0 = player.Character.HumanoidRootPart weld.Part1 = part weld.C0 = CFrame.new(0, -5, 0) end) while true do part.CFrame = part.CFrame * CFrame.fromEulerAnglesXYZ(.002,.005,.009) wait(.001) end
I'll be happy to answer any questions or concerns regarding these methods.
EDIT: Comment, to call the player in the server, you need to activate a touch-based detectable event (usu. w/ ClickDetectors or .Touched)
Server Variant of lookVector
local part = script.Parent part.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") ~= nil then local character = hit.Parent character:SetPrimaryPartCFrame(character.HumanoidRootPart.CFrame + (part.CFrame.LookVector * Vector3.new(0.05, 0, 0))) end end) while true do part.CFrame = part.CFrame * CFrame.fromEulerAnglesXYZ(.002,.005,.009) wait(.001) end
However, since this doesn't work as smoothly as the Local Variant I suggest using the first code listed above instead (placed in a LocalScript under StarterGui)