script.Parent.Touched:connect(function(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player.Team == "Red" then script.Parent.Parent.RedOccupied.Value = script.Parent.Parent.RedOccupied.Value + 1 elseif player.Team == "Blue" then script.Parent.Parent.BlueOccupied.Value = script.Parent.Parent.BlueOccupied.Value + 1 end end)
Error:
00:29:15.515 - Workspace.MountainFlag.FlagTrigger.Script:3: attempt to index local 'player' (a nil value)
What you need to do is access your character from workspace then you can use :GetPlayerFromCharacter()
EDIT: You need to make the script only detect a player. Make sure it checks if the touched part has a Humanoid.
Here is the [New] fixed script:
script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then local plr = workspace[hit.Parent.Name] --Access character from workspace. local player = game.Players:GetPlayerFromCharacter(plr) --Access (plr) if player.Team == "Red" then script.Parent.Parent.RedOccupied.Value = script.Parent.Parent.RedOccupied.Value + 1 elseif player.Team == "Blue" then script.Parent.Parent.BlueOccupied.Value = script.Parent.Parent.BlueOccupied.Value + 1 end end end)