Door Touched Not Connecting Function

Hello,
Recently I’ve been working on a script that when the scripts parent is touched it tweens a black screen on the players screen and teleports them to a different location
However, when the block is being touched it isn’t connecting the function any idea on how to fix this?

local Players = game:GetService("Players")
local TweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)
local blackScreen = game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui"):WaitForChild("BlackScreen")

-- Define teleport position
local teleportPosition = Vector3.new(0, 10, 0) -- Change this to the desired teleport position

-- Define tweens
local tweenIn = TweenService:Create(blackScreen, TweenInfo, {BackgroundTransparency = 0})
local tweenOut = TweenService:Create(blackScreen, TweenInfo, {BackgroundTransparency = 1})

local function onTouch(otherPart)
	print("WORKS")
	local character = otherPart.Parent
	local player = Players:GetPlayerFromCharacter(character)

	if player then
		-- Teleport the player
		player.Character.HumanoidRootPart.CFrame = CFrame.new(teleportPosition)

		-- Tween black screen
		blackScreen.Visible = true
		tweenIn:Play()
		tweenIn.Completed:Connect(function()
			wait(0.5) -- Duration for the black screen to stay before fading out
			tweenOut:Play()
			tweenOut.Completed:Connect(function()
				blackScreen.Visible = false
			end)
		end)
	end
end

script.Parent.Touched:Connect(onTouch)

You have defined tweens using TweenService, but you haven’t defined TweenService. Add the following line near the top of your script:

local TweenService = game:GetService("TweenService")

Local script in workspace isn’t it? Or is it a server script in workspace? Doesn’t matter which one it is. Make sure script is local and move it to StarterGui and replace script.Parent with whatever the name of the part is. game.Workspace.—Part name here?

apparently i forgot to copy it but i did write it so thats not the issue

why did this fix it exactly it worked but can you explain why

If this was a local script in workspace, the reason it didn’t work is because local scripts cannot work in the workspace since it’s not player-controlled. If this was a server script, then you can’t access the local player from a server script