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.
Your doing
Owner.Value
when the Owner vairiable is set to the value. Hope this helps!
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.