Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Attempt to index nil with 'Team' ?

This code is for an item pickup system, and I only want players on a particular team to be able to pick it up. However, I get an error when the code runs.

player = game.Players.LocalPlayer

boostPack = script.Parent
plunger = script.Parent.Parent.Plunger
needle = script.Parent.Parent.Needle
serum = script.Parent.Parent.Serum

local function onPartTouch(otherPart)
		
	local partParent = otherPart.Parent	
	local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
	
	if humanoid then
		
		if player.Team == "Doctor" then
			
			local boosts = humanoid.Parent.Boosts

			boosts.Value = boosts.Value + 1

			boostPack:Destroy()
			plunger:Destroy()
			needle:Destroy()
			serum:Destroy()
	
		end
		
	end
	
end

boostPack.Touched:Connect(onPartTouch)

1 comment

0

Is this a server or client script? Players.LocalPlayer is nil on the server.

1 answer

A player's Team is not a string, it is a reference to the actual team instance. Change line 15 to:

if player.Team == game.Teams.Doctor then

This discussion is preserved as it was. New answers, comments, and votes are closed.