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

attempt to index upvalue 'Variable' (a nil value)?

Asked by
xg1y 41
5 years ago
Edited 5 years ago

Yo so question; got a basic script here: ```lua local NPC = game.ReplicatedStorage.NPC local customer = game.ReplicatedStorage.Events.Customer local username = game.ReplicatedStorage.Events.Username local green = game.Workspace.Green.Owner.Value local red = game.Workspace.Red.Owner.Value local Owner

username.OnServerEvent:Connect(function(player) if player == green then Owner = green elseif player == red then Owner = red end end)

customer.OnServerEvent:Connect(function() if Owner.Value.."'s customer" == workspace:WaitForChild(Owner.Value.."'s customer") then print('exisiting') else print('new customer') local newNPC = NPC:Clone() newNPC.Parent = workspace newNPC.Name = Owner.Value.."'s customer" newNPC.Pathfinding.Disabled = false print('pathfinding enabled') end end) ```

and its popin this error lua attempt to index upvalue 'Owner' (a nil value)

The end goal is the create an NPC with a user's name and if an existing customer exists then it doesn't create a new one.

2 answers

Log in to vote
0
Answered by
HDWC 53
5 years ago

Your doing

Owner.Value

when the Owner vairiable is set to the value. Hope this helps!

Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

It really depends on which event fires first. It appears that the second event fires before the first one, which is why you're getting the error because Owner is still a nil variable. You can easily swap the order of when the events fire and it should fix your problem.

You're also doing Owner.Value when Owner is actually assigned to a number, not an Instance. Simply use Owner.

0
Returning with attempt to " concatenate upvalue 'Owner' " xg1y 41 — 5y
0
tostring(Owner) DeceptiveCaster 3761 — 5y
0
Infinite yield possible on 'Workspace:WaitForChild("nil's customer")' xg1y 41 — 5y
0
That's a different problem. That likely doesn't exist in the Workspace. DeceptiveCaster 3761 — 5y

Answer this question