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)