Attempt to index error

I get an error while testing my portal.

Error:
Attempt to index nil with "Fade"

Local Script:

local Player = game.Players.LocalPlayer
local TeleportService = game:GetService("TeleportService")
local TeleportEvent1 = game.ReplicatedStorage:FindFirstChild("TeleportEvent1")
local TeleportEvent2 = game.ReplicatedStorage:FindFirstChild("TeleportEvent2")
local TeleportGui = Player.PlayerGui:FindFirstChild("TeleportGui")
local TweenService = game:GetService("TweenService")

TeleportEvent1.OnClientEvent:Connect(function()
	TweenService:Create(TeleportGui.Fade, TweenInfo.new(1), {BackgroundTransparency = 0}):Play()
	task.wait(1.5)
	TeleportService:Teleport(6667412878)
end)

TeleportEvent2.OnClientEvent:Connect(function()
	TweenService:Create(TeleportGui.Fade, TweenInfo.new(1), {BackgroundTransparency = 0}):Play()
	task.wait(1.5)
	TeleportService:Teleport(2572204670)
end)

Script:

local Players = game:GetService("Players")
local teleport = script.Parent
local TeleportEvent = game.ReplicatedStorage:FindFirstChild("TeleportEvent1")
local sound = teleport.TeleportSound

local debounce = false

teleport.Touched:Connect(function(touch)
	local Player = Players:GetPlayerFromCharacter(touch.Parent)
	if not debounce and Player then
		debounce = true
		TeleportEvent:FireClient(Player)
		sound:Play()
		task.wait(3)
		debounce = false
	end
end)

Any help is appreciated, thanks.

If you are teleporting to a new place the player’s gui may not have loaded, as I think this loads in with the character.
Try using WaitForChild instead of FindFirstChild.

1 Like

Thanks, it works now, thanks for solving.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.