Night vision when changed to a team

Hello again people, I’m back, again.

So what I’m trying to make here is to make night vision for a specific team, I wanted to do this by detecting when the player changed their team, it set the lighting ambient to be brighter locally.

The issue is that it just doesn’t work, nothing in the output.
The script is local.

local Team = game:GetService("Teams")

function onTeamChange(newTeam)
	if game.Players.LocalPlayer.Team == "Beast" then
		game.Lighting.Ambient = Color3.fromRGB(120, 120, 120)
	else
		game.Lighting.Ambient = Color3.fromRGB(0, 0, 0)
	end
end

game.Players.LocalPlayer:GetPropertyChangedSignal("Team"):Connect(function()
	onTeamChange(game.Players.LocalPlayer.Team)
end)

I’ve tried using GetPropertyChangedSignal but that doesn’t seem to work.
I’ve already read through a few post but it doesn’t help me much, I just learned about the GetPropertyChangedSignal.

I really have no details on this, so this is a short one.

1 Like

I might be wrong but, what if you check the player’s team name instead:

local TeamService = game:GetService("Teams")

function onTeamChange(newTeam)
   if newTeam.Name == "Beast" then
      game.Lighting.Ambient = Color3.fromRGB(120, 120, 120)
  else
	  game.Lighting.Ambient = Color3.fromRGB(0, 0, 0)
  end
end

game.Players.LocalPlayer:GetPropertyChangedSignal("Team"):Connect(function()
	onTeamChange(game.Players.LocalPlayer.Team)
end)

You can also check if the player’s team is an instance in the teams service:

local TeamService = game:GetService("Teams")

function onTeamChange(newTeam)
   if newTeam == TeamService["Beast"] then
      game.Lighting.Ambient = Color3.fromRGB(120, 120, 120)
  else
	  game.Lighting.Ambient = Color3.fromRGB(0, 0, 0)
  end
end

game.Players.LocalPlayer:GetPropertyChangedSignal("Team"):Connect(function()
	onTeamChange(game.Players.LocalPlayer.Team)
end)

@himynamemate Update: I made a table version. (Recommended)

local TeamService = game:GetService("Teams")

local TeamAmbient = { -- Add every team that exists in here.
	["Beast"] = Color3.fromRGB(120,120,120),
	["Team Name Here"] = Color3.fromRGB(0,0,0),
}

function onTeamChange(newTeam)
	for i,v in pairs(TeamAmbient) do
		if newTeam.Name == i then
			game.Lighting.Ambient = v
		end
	end
end

game.Players.LocalPlayer:GetPropertyChangedSignal("Team"):Connect(function()
	onTeamChange(game.Players.LocalPlayer.Team)
end)

Don’t know how to use tables? Then look at this article: Tables | Roblox Creator Documentation

2 Likes

I beleive the team property isn’t a string.

try this:

local Team = game:GetService("Teams")

function onTeamChange(newTeam)
	if game.Players.LocalPlayer.Team == Team["Beast"] then
		game.Lighting.Ambient = Color3.fromRGB(120, 120, 120)
	else
		game.Lighting.Ambient = Color3.fromRGB(0, 0, 0)
	end
end

game.Players.LocalPlayer:GetPropertyChangedSignal("Team"):Connect(function()
	onTeamChange(game.Players.LocalPlayer.Team)
end)
1 Like

Nothing changed, nothing came in the output either.

The lighting remain the same, odd, because I thought this would work surely.

try using brick color:

local Team = game:GetService("Teams")

function onTeamChange(newTeam)
	if game.Players.LocalPlayer.TeamColor== Team.Beast.TeamColor then
		game.Lighting.Ambient = Color3.fromRGB(120, 120, 120)
	else
		game.Lighting.Ambient = Color3.fromRGB(0, 0, 0)
	end
end

game.Players.LocalPlayer:GetPropertyChangedSignal("TeamColor"):Connect(function()
	onTeamChange(game.Players.LocalPlayer.Team)
end)
1 Like

It doesn’t change anything either, I am really confused.

I do not have much information on teams, but I suggest using an alternative if it still doesn’t seem to work. Try:

local Teams = game:GetService("Teams")
local Player = game.Players.LocalPlayer
print("Script online")

function onTeamChange(newTeam)
    print("Function working")

    if newTeam == Teams.Beast then
        game.Lighting.Ambient = Color3.fromRGB(120, 120, 120)
        print("Found a scary beast")
    else
	    game.Lighting.Ambient = Color3.fromRGB(0, 0, 0)
        print("Not found a scary beast")
    end
end

Player:GetPropertyChangedSignal("Team"):Connect(function()
    onTeamChange(Player.Team)
end)

Try this maybe?

1 Like

Sorry for delayed reply, I went to sleep.
Unfortunately nothing printed in the output nor the lighting changed.

If nothing is printed in the output you’re probably running the script from the wrong place. Put the code in a LocalScript inside StarterPlayerScripts.

1 Like

Am I doing this right?

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

game.Teams.Beast.PlayerAdded:Connect(function(Plr)
	if Plr.Name == Player.Name then
		game.Lighting.Ambient = Color3.fromRGB(120, 120, 120)
	else
		game.Lighting.Ambient = Color3.fromRGB(0, 0, 0)
	end
end)
1 Like

Oh my god I put it in StarterPack I just realized now