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

How do I check a part's position?

Asked by 3 years ago

I'm trying to make a sliding door and I can't figure out how to check for the door's position.

local part = script.Parent
local door = script.Parent.Parent.Door
local debounce = false
local doorfunc = require(script.Parent.Parent.Door.ModuleScript)

    script.Parent.Touched:Connect(function(hit)
    if debounce == false then
        debounce = true
        if hit.Parent.level.Value >= 2  then
            if door.Position == Vector3.new(36.925, 2.975, 40.4) then
            doorfunc.Open()
            door.Open:Play()
            elseif door.Position == Vector3.new(36.925, 8.675, 40.4) then
            doorfunc.Close()
            door.Close:Play()
            else print("Position is not found or is either moving")
        end
        end
        if hit.Parent.level.Value <= 1 then
            door.Audio:Play()
        end
        wait(1)
        debounce = false
    end
end)

This is what checks the door's position, but it doesn't function correctly. Also the module script has some tween animations in it to move the door.

0
try putting print on each line to see what's the not working line+ i have a problem with debounce can you explain it if u can please? az1339and339 0 — 3y
0
debounce is basically a delay so that people can't spam something Zeta_Dev 34 — 3y
0
If you want to explain debounce function in script, contact me on discord - lukiny9000_2#0558 BeautifulAuraLover 371 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

Hello, try to not use Vector3.new() which defines new position, try this one:

local part = script.Parent
local door = script.Parent.Parent.Door
local debounce = false
local doorfunc = require(script.Parent.Parent.Door.ModuleScript)

    script.Parent.Touched:Connect(function(hit)
    if debounce == false then
        debounce = true
        if hit.Parent.level.Value >= 2  then
            if tostring(door.Position) == "36.925, 2.975, 40.4" then -- Try to not use Vector3.new
            doorfunc.Open()
            door.Open:Play()
            elseif tostring(door.Position) == "36.925, 8.675, 40.4" then
            doorfunc.Close()
            door.Close:Play()
            else print("Position is not found or is either moving")
        end
        end
        if hit.Parent.level.Value <= 1 then
            door.Audio:Play()
        end
        wait(1)
        debounce = false
    end
end)
0
It is still printing position is not found or is either moving after I applied your edits. Zeta_Dev 34 — 2y
Ad

Answer this question