Checking if a Player is on a team at all times

SCRIPT---------------- START

> local Resident = game:GetService("Teams").Resident
> 
> local DPD = game:GetService("Teams").DPD
> 
> if .Team == Resident then
> 
> wait(10)
> 
> local amount = game.Workspace.Jobs.ResidentPayment.Amount.Value
> 
> game.ReplicatedStorage.MoneyEvent:FireAllClients(amount)
> 
> elseif .Team == DPD then
> 
> wait(10)
> 
> local amount = game.Workspace.Jobs.DPD_Payement.Amount.Value
> 
> game.ReplicatedStorage.MoneyEvent:FireAllClients(amount)
> 
> end

SCRIPT---------------- END

If Someone could assist as I need to find out if a player is on a team constantly due to a money system that has different wages for different jobs.

FoxysFire_Photo#4252

1 Like

What is this variable? I don’t see this anywhere in your script

So That’s where I need to see what team the player is on where I am having issues with, That’s what I need finding what I put before that as it needs to have the team at all times.

So, use a loop to loop through every player in the game and check their team.

Just create a local player variable and put localPlayer.Team

If this event adds the money then my god please change it. Do not add (or stats) on the client. Also why are you even firing all clients

What would that Local Player Value be?

game.Players.LocalPlayer

I’m pretty sure it’s a reg/server script hence firing all clients

Its a FM Easy script. Ik Its easy to exploit its just what he requested so I am just trying to sort that team issue.

What kinda script is this (the one you gave us), Local, Server?

Sort of new to scripting so going to say server. Its in workspace under the money folder

Server just shows a regular scroll, local shows a little person in front of the same scroll

Ok, then no need to use a remote event just add the money in that script.

Server Script Then thanks

FoxysFire_Photo#4252

Now I get attempt to index nil with ‘Team’

Did you try what I said? It should work.

Speaking with the Founder He wants it to be Remotes so how it is just needing that Team line to be fixed. Ik I want to change it but I work to Clients use’s and needs.

I agree with some of the other posts here, the easiest way to do this would likely be to just loop through all active Players in-game, and send the appropriate amount of money to each Player based on their current team.

One of the main differences in my snippet below to your initial script is that I loop through the set of Players in-game once per payment cycle (every 10 seconds), and fire the MoneyEvent for each individual Player. This allows you to send the appropriate amount of money (pay) to a Player based on their team alone. (I’m using RemoteEvent:FireClient(plr, moneyAmt) instead of RemoteEvent:FireAllClients(moneyAmt).

--Setup variables

--Assign MoneyEvent to a variable... etc.

--Define the amount to pay players on each team
local residentPayAmt = game.Workspace.Jobs.ResidentPayment.Amount.Value
local DPDPayAmt = game.Workspace.Jobs.DPDPayment.Amount.Value

--Define the name of each possible team for payment
local RESIDENT_TEAM = "Resident"
local DPD_TEAM = "DPD"

--The length of time to wait in-between paying players
local PAY_WAIT_TIME = 10

--Core Payment loop
while true do
	
	for _, plr in pairs(game:GetService("Players"):GetPlayers()) do
		
		--Check if the Player is on a team
		if plr.Team then
			
			--Send the Resident Pay amount to Players on the Resident Team
			if plr.Team.Name == RESIDENT_TEAM then
				MoneyEvent:FireClient(plr, residentPayAmt)
				
			--Send the DPD Pay amount to Players on the DPD Team
			elseif plr.Team.Name == DPD_TEAM then
				MoneyEvent:FireClient(plr, DPDPayAmt)
			end
			
			--Add additional teams for payment as needed
		end
	end
	
	task.wait(PAY_WAIT_TIME)
end

One parting note based on the discussion here:

  • It’s true that you’d probably want to store the amount of money each player has on the server independent of the client. If you rely solely on the client for actions such as purchases, it could be very easy to exploit as you’d have no way to verify the actual amount of money the Player should have. I’m assuming the person you’re working for wants remote communication to update GUI elements locally for each Player.

I hope this helps!

Will this still pay if the user / player switches team