Log in to vote

How do I anchor the player to the part to prevent clipping?

Asked by 1 month ago
Edited 1 month ago

Hello all,

I’m trying to create an elevator for my game, but I’m not sure how to prevent players from clipping through the floor when the TweenService animation plays. (To clarify, I used the TweenService animator plugin.)

I would like to know if there is a way to anchor the player to the part (it is named “Elevator” so the player doesn’t clip.

animator = require(script.Parent.Elevator.Animator)

    script.Parent.Button.ClickDetector.MaxActivationDistance = 0
    script.Parent.Button.ClickDetector.MaxActivationDistance = 32

I'm not sure how to anchor the player to the part so they dont move until the script is done executing, can anyone show me how it works/point me in the right direction?

Try using BodyPositions! MattVSNNL 378 — 1mo

2 answers

Log in to vote
Answered by
MattVSNNL 378 Moderation Voter
1 month ago

BodyPositions are basically Tweening but the player's character moves with it! I've seen with normal TweenService Tweening that it doesn't bring the player!

To save you time I made a small script for it! I don't know if it works but I don't know why it wouldn't!

-- Welding all the parts together
for _, v in pairs(workspace:FindFirstChild("Elevator"):GetDescendants()) do
    if v:IsA("BasePart") then

        v.Anchored = false

        local weldConstraint ="WeldConstraint")
        weldConstraint.Part0 = v
        weldConstraint.Part1 = workspace:FindFirstChild("Elevator"):FindFirstChild("ElevatorFloor")
        weldConstraint.Parent = workspace:FindFirstChild("Elevator"):FindFirstChild("ElevatorFloor")


local bodyPosition ="BodyPosition")
bodyPosition.Parent = workspace:FindFirstChild("Elevator"):FindFirstChild("ElevatorFloor") -- Change that to the Elevator floor!

bodyPosition.MaxForce =, math.huge, math.huge)
bodyPosition.Position = workspace:FindFirstChild("Elevator"):FindFirstChild("ElevatorFloor").Position

-- When the elevator moves!
bodyPosition.D = 700
bodyPosition.Position = workspace:FindFirstChild("Elevator"):FindFirstChild("ElevatorFloor").Position +, 50, 0) -- Change to the position you want!
Thank you for trying to help, but I'm not exactly sure where to put this script. I tried making a new script in the same model and editing what is needed, but the player did not anchor to the elevator part. I should let you know, that this is more of a lift than an elevator. Its a single part that goes down when a button is pressed through the use of TweenService - kingsworld9 14 — 1mo
- and back up again automatically again through the use of TweenService. I used the TweenService animator plugin, and this "elevator" only has 2 floors. One, the top, and 2, the bottom. kingsworld9 14 — 1mo
There are no "ElevatorFloors" as it is simply a "go down, come back up" after a button is pressed. What I want to know is how the player can be anchored BEFORE this script executes, so they will be anchored for the remainder of the script duration and then unanchored when the script ends. kingsworld9 14 — 1mo
maybe make the player unable to move (like set their speed to 0) then use a loop that make sures the player's position is always greater or equal to the elevator's position to prevent them clipping ZeroToH3ro 82 — 1mo
View all comments (3 more)
Uhmm BodyPosition is deprecated.. T3_MasterGamer 227 — 1mo
Use the script I sent MattVSNNL 378 — 1mo
Also the script can be anywhere MattVSNNL 378 — 1mo
Log in to vote
Answered by 1 month ago

Try using WeldConstraint. When the Tween is played, you create the WeldConstraint immediately.

Tween:Play() --you play the tween
local weldConstraint ="WeldConstraint")

Next, make sure your elevator model has a PrimaryPart, or an invisible part in the middle of the model that connects all of the instances/parts inside that model. (like the HumanoidRootPart of the character)

The Part0 of the constraint should be the player's HumanoidRootPart or torso, and the Part1 should be the PrimaryPart of the elevator.

(if this script below doesn't work, try making the PrimaryPart of the model and edit the PrimaryPart of the model by clicking the model and click PrimaryPart under Pivot, and click the part or the middle invisible part of the elevator that serves as an anchor)

If you're lazy to read the above if the script below doesn't work (lol) then just edit the PrimaryPart in the script into any part from the model. (like turning weldConstraint.Part1 = model.PrimaryPart to weldConstraint.Part1 = model."AnyPartNameHere")

weldConstraint.Part0 = (plr.Character or plr.CharacterAdded:Wait()):FindFirstChild("HumanoidRootPart") or (plr.Character or plr.CharacterAdded:Wait()):FindFirstChild("Torso") --the humrootpart or torso
weldConstraint.Part1 = model.PrimaryPart --the elevator model
weldConstraint.Parent = model.PrimaryPart
weldConstraint.Name = "CharacterMeldWeld"

Then after that, add wait() or task.wait() and inside the parenthesis, add the length of the tween plays. (no difference between wait() and task.wait() but task.wait() is more precise and much recommend to use)

task.wait(--number of seconds how long your tween takes) --you can change this to wait() if you like

And after that, remove the WeldConstraint so the player can move freely. (the player cannot move if the elevator is going up or down because of WeldConstraint)

local theConsTraintWeldPart = model.PrimaryPart --or the part of the elevator model where you put the constraint in

You're done! I used this method in one of my games used for testing. (If you're wondering what game, here it is! and I'M NOT ADVERTISING MY GAME!)

Lemme know if there are errors or mistakes, or parts you don't understand. Have a good day! ^^

Answer this question