Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

		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()
			wait()
		end

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

		local overlay = Instance.new("Frame")
		overlay.Size = UDim2.new(1, 0, 1, 0)
		overlay.Position = UDim2.new(0, 0, 0, 0)
		overlay.BackgroundColor3 = Color3.new(0, 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
				wait()
			end
			overlay.BackgroundTransparency = fadeIn and 0 or 1
		end

1 comment

0

BTW, ChatGPT is amazing!

1 answer

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.