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

Same line of code, three different outcomes?

Asked by
Faazo 84
5 years ago
Edited 5 years ago

I have a line of code:

print (#game.workspace.Automaticdoor.Detector1:GetTouchingParts())

This line of code has been repeated three times throughout my script. Here is my script:

wait(5)
    print (#game.workspace.Automaticdoor.Detector1:GetTouchingParts())

local TweenService = game:GetService("TweenService")

local Door1 = script.Parent:WaitForChild("Door1").Frame

local Door2 = script.Parent:WaitForChild("Door2").Frame

local tweeningInformation = TweenInfo.new(

1,

Enum.EasingStyle.Sine,

Enum.EasingDirection.Out,

0,

false,

0

)

local Door1Open = {CFrame = CFrame.new(-40.089, 4.304, -6.327)}

local Door2Open = {CFrame = CFrame.new(-40.089, 4.304, 9.013)}

local Door1Close = {CFrame = CFrame.new(-40.089, 4.304, -1.327)}

local Door2Close = {CFrame = CFrame.new(-40.089, 4.304, 4.013)}

local Tween1Open = TweenService:Create(Door1,tweeningInformation,Door1Open)

local Tween1Close = TweenService:Create(Door1,tweeningInformation,Door1Close)

local Tween2Open = TweenService:Create(Door2,tweeningInformation,Door2Open)

local Tween2Close = TweenService:Create(Door2,tweeningInformation,Door2Close)



dooropen = false





script.Parent.Detector1.Touched:Connect(function()

if dooropen == false then

dooropen = true

Tween1Open:Play()

Tween2Open:Play()

wait(2)

while wait(.1) do

if #game.workspace.Automaticdoor.Detector1:GetTouchingParts() == 3 then

Tween1Close:Play()

Tween2Close:Play()

dooropen = false

end



if dooropen == false then break end

end

print (#game.workspace.Automaticdoor.Detector1:GetTouchingParts())

end

end)



print (#game.workspace.Automaticdoor.Detector1:GetTouchingParts())

As you can see, there are three duplicates of this line of code; one is at the top, one is near the bottom and one is at the bottom. Here is my problem, I'm trying to incorporate this line of code into my script, but it doesn't work. This is because it prints something different depending on where it is used in the script. The first one prints 0, the second one prints 3 and the third one prints 5. However, they should stay the same each time. Also, the line of code at the top and bottom of the script run simultaneously and still print different numbers. Why is this happening? Help is appreciated.

0
Is the goal of this script just to open a door once it has been touched and close after 2 seconds? MegaManSam1 207 — 5y
0
Its supposed to open once it has been touched and close when nobody is touching it. Faazo 84 — 5y
0
`while wait(t) do if terminatingExpression then break end` seriously? `while not terminatingCondition do wait(t) end` is what you should be doing. Also parts that have collisions disabled do not count as a touching part. User#24403 69 — 5y

Answer this question