Scripting Helpers is winding down operations and is now read-only. More info→
Log in to vote

Script Error attempt to index nil with 'Character',can you fix this?

Asked by
Gigaset39 111
1 year ago

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

        local Players = game:GetService("Players")
        local TweenService = game:GetService("TweenService")

        local player = Players.LocalPlayer
        local character = player.Character or player.CharacterAdded:Wait()
        local humanoid = character:WaitForChild("Humanoid")
        local rootPart = character:WaitForChild("HumanoidRootPart")
        local camera = workspace.CurrentCamera

        -- Wait for character to be initialized
        while not character do
            character = player.Character or player.CharacterAdded:Wait()

        -- Create black screen overlay
        local gui ="ScreenGui")
        gui.IgnoreGuiInset = true
        gui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
        gui.Parent = player.PlayerGui

        local overlay ="Frame")
        overlay.Size =, 0, 1, 0)
        overlay.Position =, 0, 0, 0)
        overlay.BackgroundColor3 =, 0, 0)
        overlay.BackgroundTransparency = 1
        overlay.Parent = gui

        -- Function to fade screen in/out
        local function fadeScreen(duration, fadeIn)
            local startTime = tick()
            local endTime = startTime + duration
            while tick() < endTime do
                local timeFraction = (tick() - startTime) / duration
                overlay.BackgroundTransparency = fadeIn and (1 - timeFraction) or timeFraction
            overlay.BackgroundTransparency = fadeIn and 0 or 1
BTW, ChatGPT is amazing! Gigaset39 111 — 1y

1 answer

Log in to vote
Answered by
manith513 121
1 year ago

This should be in a local script. I'm assuming that because you used chatGPT that you forgot to do this. Put it into a local script and the error should subside.


Answer this question