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

What does attempt to index upvalue 'Character' (a nil value) mean?

local Player=game.Players.LocalPlayer
local Character=Player.Character
local Mouse=Player:GetMouse()

Mouse.KeyDown:connect(function(K)
	if K=="q" then
		local Frog=workspace.Frog:Clone()
		Frog.Parent=workspace
		Frog.CFrame=Character.Torso.CFrame+Vector3.new(0,5,0)
		while Mouse.KeyDown:connect(function(Q)end)do
			wait(1)
			if Q=="q" then
				Frog.Size=Frog.Size+Vector3.new(.1,.1,.1)
			end
		end
		
			Mouse.Button1Down:connect(function()
		Frog.Anchored=false
		Frog.BodyPosition.position=Mouse.Hit.p
		local Debris=game:GetService("Debris")
		wait(5)
		Frog.BrickColor=BrickColor.new("Really black")
		Debris:AddItem(Frog,5)
		end)
	end
end)

This works fine until I start a server, and the output says

attempt to index upvalue 'Character' (a nil value)

what am I doing wrong? thank you in advanced

1 answer

✓ Accepted answer

You're trying to use Character but it is in fact nil (meaning not defined).

This happens to be because the Character has not yet loaded for the player.

We can make sure it has by beginning the script with a pause until Character is there:

Player = game.Players.LocalPlayer
repeat
	wait()
until Player.Character
Character = Player.Character

2 comments

0

heh its always the little things that make me feel dumb :P

0

forgot to say thanks

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