Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I check a part's position?

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.

3 comments

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?

0

debounce is basically a delay so that people can't spam something

0

If you want to explain debounce function in script, contact me on discord - lukiny9000_2#0558

1 answer

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)

1 comment

0

It is still printing position is not found or is either moving after I applied your edits.

This discussion is preserved as it was. New answers, comments, and votes are closed.