So this is a simple script where a player steps on a brick and it checks to see if it is an admin or not. If the player is not an admin, they die. If the player is, the brick turns yellow. I wrote the script corresponding to a scripting tutorial: https://www.youtube.com/watch?v=jQ0iClyt_zA&t=312s
Here is the script with the bindable function and list of admins:
admins = {"crystalclay", "Player1", "Player2", "John", "Bob"} script.GetList.OnInvoke = function(name) isAdmin = false for i,v in pairs (admins) do if name == v then isAdmin = true break end end if isAdmin == true then return true else return false end end
The problem with this script is that, on line 4, the first "isAdmin" is underlined in blue.
Here is the script for the part:
script.Parent.Touched:connect(function(hit) humanoid = hit.Parent:FindFirstChild("Humanoid") -- The first "humanoid" is underlined in blue if humanoid then playerName = hit.Parent.Name -- "playerName" is underlined in blue isAdmin = game.Workspace.ListoAdmins.GetList:Invoke(playerName) -- "isAdmin" is underlined in blue if isAdmin == true then Part.BrickColor = BrickColor.new("Bright Yellow") --"Part" is underlined in blue else humanoid.Health = 0 end end end)
I do not understand why there are blue underlines as I double checked and typed the script exactly as Peaspod did in this video.
Here is the error message I'm getting: 21:51:31.537 - Workspace.Part.Script:7: attempt to index global 'Part' (a nil value)
Since you wanted an explanation, Part
was underlined in blue because it wasn't defined anywhere in the script. If you had added local Part = script.Parent
at the beginning of your second script, it would have worked.
As for your other blue underlines, this typically happens because it defined globally instead of locally (eg. isAdmin = blah
instead of local isAdmin = blah
). It is recommended to define variables locally wherever and whenever possible because a) it takes less time to access local variables, and b) global variables are shared between different "scopes". For example:
function a() g = 2 end function b() print(g) end a() b() -- prints 2, even though g wasn't defined anywhere inside b(). function c() local l = 2 end function d() print(l) end c() d() -- prints nil, because l wasn't defined in d()'s scope. This is clear.