Script Error attempt to index nil with 'Character',can you fix this?
Hello world, im using ChatGPT to modify the folowing script, but it, its a little bit.. yeah..
in the rror says: attempt to index nil with 'Character' -line 5
01 | local Players = game:GetService( "Players" ) |
02 | local TweenService = game:GetService( "TweenService" ) |
04 | local player = Players.LocalPlayer |
05 | local character = player.Character or player.CharacterAdded:Wait() |
06 | local humanoid = character:WaitForChild( "Humanoid" ) |
07 | local rootPart = character:WaitForChild( "HumanoidRootPart" ) |
08 | local camera = workspace.CurrentCamera |
12 | character = player.Character or player.CharacterAdded:Wait() |
17 | local gui = Instance.new( "ScreenGui" ) |
18 | gui.IgnoreGuiInset = true |
19 | gui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling |
20 | gui.Parent = player.PlayerGui |
22 | local overlay = Instance.new( "Frame" ) |
23 | overlay.Size = UDim 2. new( 1 , 0 , 1 , 0 ) |
24 | overlay.Position = UDim 2. new( 0 , 0 , 0 , 0 ) |
25 | overlay.BackgroundColor 3 = Color 3. new( 0 , 0 , 0 ) |
26 | overlay.BackgroundTransparency = 1 |
30 | local function fadeScreen(duration, fadeIn) |
31 | local startTime = tick() |
32 | local endTime = startTime + duration |
33 | while tick() < endTime do |
34 | local timeFraction = (tick() - startTime) / duration |
35 | overlay.BackgroundTransparency = fadeIn and ( 1 - timeFraction) or timeFraction |
38 | overlay.BackgroundTransparency = fadeIn and 0 or 1 |