In my puzzle game, I have a moving platform. I want it so that when players, or cubes (If it matters, yes they are tagged) are put on top of it, and it is moved, that they move with the platform.
Currently, this is the structure I have in explorer:
And this is the code found in the MovingPlatformScript:
local TweenService = game:GetService("TweenService")
local CollectionService = game:GetService("CollectionService")
local platform = script.Parent
local glowingPart : Part = platform.Platform.GlowingPart
local root : Part = platform.Platform.Root
local pointAEvent = platform.GoToPointA
local pointBEvent = platform.GoToPointB
local pointA = platform.Parent.PointA
local pointB = platform.Parent.PointB
pointAEvent.Event:Connect(function()
local tween = TweenService:Create(root, TweenInfo.new(1, Enum.EasingStyle.Linear), { CFrame = pointA.CFrame + Vector3.new(0, 0.75, 0) })
tween.Completed:Connect(moveFinished)
tween:Play()
moveStart()
end)
pointBEvent.Event:Connect(function()
local tween = TweenService:Create(root, TweenInfo.new(1, Enum.EasingStyle.Linear), { CFrame = pointB.CFrame + Vector3.new(0, 0.75, 0) })
tween.Completed:Connect(moveFinished)
tween:Play()
moveStart()
end)
function moveStart()
glowingPart.Color = Color3.new(0, 1, 0)
script.Move:Play()
end
function moveFinished()
glowingPart.Color = Color3.new(1, 0, 0)
script.Move:Stop()
script.End:Play()
end
When the PointA event is fired, it causes the platform to move towards a point above an invisible part named “PointA”. And vice versa with PointB.
(This is using tweens at the moment.)
But currently, when a player stands on top of it, they slide right off.
I tried testing with BodyPosition, but I found that anything other than players also slides off.
And welding wont working. I’ve already seen plenty of posts warning against this for many reasons, in this scenario, it’s because I want players to still be able to move on top of it.
If I’m using BodyPosition, I don’t want to have to manually add a Humanoid to every cube (although I suppose I could script it) and besides, I have sound effects/glowing brick effect that I want to activate once the tween finishes, and as far as I am concerned I can’t detect once it finishes moving.
I’ve heard about raycasts, but the thought of them sounds very daunting. If this is the way, can anybody break down the code that way I can implement it and understand how it works?
What’s the best/any way to achieve what I want?
I hope I’m not being too picky, if I’m missing anything or need more information, please let me know.