I am currently using a ‘touched’ function to let the player leave the level by fading into a black ui frame once the leaderstat named ‘Items’ is is 5, but it keeps giving me an error saying this:
Workspace.Map1.Exit.Script:5: attempt to index nil with 'WaitForChild'
Here is the full script:
local TweenService = game:GetService('TweenService')
script.Parent.Touched:Connect(function(player)
local plr = game.Players:GetPlayerFromCharacter(player)
if plr:WaitForChild("leaderstats").Items.Value == 5 then
game.Workspace.WooScary.AI.Disabled = true
local load = plr.PlayerGui.PlayScreen.Load
TweenService:Create(
load,
TweenInfo.new(2),
{BackgroundTransparency = 1}
):Play()
wait(2)
TweenService:Create(
load,
TweenInfo.new(2),
{BackgroundTransparency = 0}
):Play()
end
end)
Does anyone have a solution?