How to fix: attempt to index global 'n' (a number value) ?
Asked by
6 years ago Edited 6 years ago
I'm trying to put a gui's adornee on the closest part. The part is spawned when people click a button. I tried to use this script:
01 | local plrName = script.Parent.Name |
02 | local rK = game.Players:GetPlayerFromCharacter(script.Parent).PlayerGui:WaitForChild( "RKeyGen" ) |
05 | for i, v in pairs (game.Workspace.Bricks:GetChildren()) do |
06 | if v.Name = = plrName then |
07 | local pPos = v.Position |
08 | local lPos = script.Parent:FindFirstChild( "HumanoidRootPart" ).Position |
09 | local pAvg = (pPos.X + pPos.Y + pPos.Z)/ 3 |
10 | local lAvg = (lPos.X + lPos.Y + lPos.Z)/ 3 |
11 | local sAway = math.abs(pAvg - lAvg) |
12 | v:WaitForChild( "NumVal" ).Value = sAway |
16 | for i, v in pairs (game.Workspace.Bricks:GetChildren()) do |
17 | if v.Name = = plrName then |
19 | if v:WaitForChild( "NumVal" ).Value > n and v:WaitForChild( "NumVal" ).Value < 10 then |
22 | n.Value = (v:WaitForChild( "NumVal" ).Value) |
25 | n = (v:WaitForChild( "NumVal" ).Value) |
but it says "attempt to index global 'n' (a number value)"
Also, the person who spawned the part can only see the gui on that part.
Any help?