Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a sliding brick with BodyPosition?

Asked by 5 years ago
local enabled = true

function onTouched(human)
    print("Touched")
    local touchpart = script.Parent
    local door = script.Parent.Parent.Door
    local h = human.Parent:FindFirstChildWhichIsA("Humanoid")
    if h and enabled then
        enabled = false
        print(1)
        door.BodyPosition.Position = script.Parent.Parent.End.Position
        wait(3)
        door.BodyPosition.Position = script.Parent.Parent.Start.Position
        enabled = true
        wait(1)
        print("Done")
    end
end

script.Parent.Touched:Connect(onTouched)

I put this script into the part that the player touches. When I run the game, the brick goes to position 0,0,0. (Prints are just there to try to pinpoint problem) What's wrong with it?

0
You shouldn’t use FindFirstChildWhichIsA, use FindFirstChildOfClass. User#19524 175 — 5y
0
Have the print statements pinpointed the problem? Also, you should check script.Parent.Parent.End.Position and .Start.Position. And use :WaitForChild() or :FindFirstChild() to make sure you're not indexing something that doesn't exist. chomboghai 2044 — 5y

Answer this question