Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Attempt to index nil with 'Team' ?

Asked by 3 years ago

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)
0
Is this a server or client script? Players.LocalPlayer is nil on the server. COUNTYL1MITS 312 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

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
Ad

Answer this question