Script wont work past the first line

This is the second scripting support ive posted in 5 days. . .yay. . .

anyway, i am trying to make a door open when you hit it with a keycard, BUT (theres always a but), it will not work. at all. i tried to make it print stuff to see where it was stuck and i got the answer. . .

print("1")
local parkAccessories = game.Workspace:FindFirstChild("Park Accesories")
local Part = parkAccessories:FindFirstChild("KeycardDoor").DoorPart
local keycardDoor = parkAccessories:FindFirstChild("KeycardDoor")
local slide = keycardDoor:FindFirstChild("Slide") 

local TweenService = game:GetService("TweenService") 

local TweenInfo = TweenInfo.new(
		2,
		Enum.EasingStyle.Sine,
		Enum.EasingDirection.Out,
		1,
		false,
		1
) 

local goal = {Position = keycardDoor:FindFirstChild("DoorOpen").Position}
local reverseGoal ={Position = keycardDoor:FindFirstChild("DoorClose").Position}
	
local Tween = TweenService:Create(Part, TweenInfo, goal)

local reverseTween = TweenService:Create(Part, TweenInfo, reverseGoal)
print("2")

slide.Touched:Connect(function(hit)
	if hit.Parent.Name == "Keycard" then
		print("3")
		Tween:Play()
		wait(3)
		reverseTween:Play()
		print("4")
	end
end)

it only gets to “1”
i cant figure out why it will not work the rest of the way. i have spent many days trying to figure this out.
what am i doing wrong???

1 Like

Are you getting any errors? You can check them in the Output

1 Like

That’s surely because one of your variable between the 1 and 2 didn’t found the referenced instance.

Wait i just noticed that the goals of the tweens are wrong.

local goal = {Position = game.Workspace["Park Accesories"].KeycardDoor.DoorOpen.Position}
local reverseGoal = {Position = game.Workspace["Park Accesories"].KeycardDoor.DoorClose.Position}
2 Likes

you could not be getting the first variable correctly. try to use findfirstchild when indexing

local Part = game.Workspace:FindFirstChild("Park Accesories"):FindFirstChild("KeycardDoor"):FindFirstChild("DoorPart")

this will at least give yoiu an error

1 Like

yes,
image
i looked around for what this error was but all the things i found said it was because it was a model, but the part DoorPart isnt a model.

It can help you where the script is failing and pinpoint:

print("1")

local parkAccessories = game.Workspace:FindFirstChild("Park Accesories")
if not parkAccessories then
    warn("Park Accesories not found in Workspace")
    return
end

local keycardDoor = parkAccessories:FindFirstChild("KeycardDoor")
if not keycardDoor then
    warn("KeycardDoor not found in Park Accesories")
    return
end

local Part = keycardDoor:FindFirstChild("DoorPart")
if not Part then
    warn("DoorPart not found in KeycardDoor")
    return
end

local slide = keycardDoor:FindFirstChild("Slide")
if not slide then
    warn("Slide not found in KeycardDoor")
    return
end

local TweenService = game:GetService("TweenService")

local TweenInfo = TweenInfo.new(
        2,
        Enum.EasingStyle.Sine,
        Enum.EasingDirection.Out,
        1,
        false,
        1
)

local goal = keycardDoor:FindFirstChild("DoorOpen")
if not goal then
    warn("DoorOpen not found in KeycardDoor")
    return
end

local reverseGoal = keycardDoor:FindFirstChild("DoorClose")
if not reverseGoal then
    warn("DoorClose not found in KeycardDoor")
    return
end

local Tween = TweenService:Create(Part, TweenInfo, {CFrame = goal.CFrame})
local reverseTween = TweenService:Create(Part, TweenInfo, {CFrame = reverseGoal.CFrame})

print("2")

slide.Touched:Connect(function(hit)
    print("Slide touched")
    if hit.Parent and hit.Parent.Name == "Keycard" then
        print("3")
        Tween:Play()
        wait(3)
        reverseTween:Play()
        print("4")
    else
        print("Touched by: " .. tostring(hit.Parent.Name))
    end
end)
1 Like

apologies if im tripping, but why are you defining a goal as an OBJECT and not the property

goals should look like:

{Position = DoorClose.Position}

btw, can we see a screenshot of your explorer?

1 Like

yes, sorry i fixed it
i also moved the script under DoorPart
image

1 Like

i tried this and it got to “4” but the tweens didnt play and there were no warnings

edit: i made some changes and figured out that the tweens dont work, i guessed that before but now i have confirmation. still cant figure out why they dont work

show us your code, otherwise we can’t help you much

Let me know if this works.

-- this script is in ServerScriptService
print("1")

local Part = game.Workspace["Park Accesories"].KeycardDoor.DoorPart

local slide = game.Workspace["Park Accesories"].KeycardDoor.Slide

local TweenService = game:GetService("TweenService")

local TweenInfo = TweenInfo.new(
		2,
		Enum.EasingStyle.Sine,
		Enum.EasingDirection.Out,
		1,
		false,
		1
)

local goal = game.Workspace["Park Accesories"].KeycardDoor.DoorOpen.Position

local reverseGoal = game.Workspace["Park Accesories"].KeycardDoor.DoorClose.Position
	
local Tween = TweenService:Create(Part, TweenInfo, goal)

local reverseTween = TweenService:Create(Part, TweenInfo, reverseGoal)

print("2")

slide.Touched:Connect(function(hit) 
	if hit.Parent.Name == "Keycard" then
		print("3")
		Tween:Play()
		wait(3)
		reverseTween:Play()
		print("4")
	end
end)

its in the first topic.
the only change i made was adding print("tween failed to play") if it had failed (which it had)

  1. Typo in variable name:
    It seems like there is a typo in your code where you define the reverseGoal table. You have written Postition instead of Position. This typo might prevent the reverseTween from executing correctly.
print("1")

local Part = game.Workspace["Park Accesories"].KeycardDoor.DoorPart
local slide = game.Workspace["Park Accesories"].KeycardDoor.Slide
local TweenService = game:GetService("TweenService")

local TweenInfo = TweenInfo.new(
    2,
    Enum.EasingStyle.Sine,
    Enum.EasingDirection.Out,
    1,
    false,
    1
)

local goal = { Position = game.Workspace["Park Accesories"].KeycardDoor.DoorOpen.Position }
local reverseGoal = { Position = game.Workspace["Park Accesories"].KeycardDoor.DoorClose.Position }

local Tween = TweenService:Create(Part, TweenInfo, goal)
local reverseTween = TweenService:Create(Part, TweenInfo, reverseGoal)

print("2")

slide.Touched:Connect(function(hit)
    if hit.Parent.Name == "Keycard" then
        print("3")
        Tween:Play()
        wait(3)
        reverseTween:Play()
        print("4")
    end
end)

where did you place the print??

this sounds ai generated, and there was never a typo (if my brain didnt fail me)

sorry, that was only in the topic, the script in roblox studio is correct

Oh my daise so that was in the topic only my bad

1 Like

But idk I just saw position and was what?

1 Like
Tween:Play()
		if not Tween:Play() then
			warn("Tween Failed to play")
		end

i had deleted it for some reason but everything else is the same

does it print 3 tho?
and are YOU really hitting the slide with the “Keycard”?