Attempt to index nil with 'Team'

Hey gamers, I’m attempting to make a script that lets only one team lock and unlock a door, however I keep getting the error attempt to index nil with 'Team'. I have looked for solutions but I can’t find anything helpful.

Here’s the script:

local plr = game:GetService("Players").LocalPlayer
local Teams = game:GetService("Teams")

script.Parent.Triggered:Connect(function()
	if script.Parent.Parent.Parent.Opener.ProximityPrompt.Script.open.Value == false then
		if plr.Team == Teams["Security"] then
			if script.locked.Value == true then
				script.locked.Value = false
				script.Parent.ActionText = "Lock"
			else
				script.locked.Value = true
				script.Parent.ActionText = "Unock"
			end
		end
	end
end)

attempt to index nil with 'Team' means that plr is nil
Is this a local script?

oh, right, i completely forgot that LocalPlayer only works in a local script. This is not a local script, but it can’t be. Are there any alternatives I could use?

.Triggered probably provides the player that activated it as an argument, so try doing

script.Parent.Triggered:Connect(function(plr)
1 Like

yanderedev core lol

btw, make sure to change this

good luck scripting :star:

1 Like

yanderedev core lol

omg no :sob:
i don’t think i would be able to use and here otherwise it wouldnt work

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.