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

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

Asked by
tumadrina 179
9 years ago
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

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

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
0
heh its always the little things that make me feel dumb :P tumadrina 179 — 9y
0
forgot to say thanks tumadrina 179 — 9y
Ad

Answer this question