Help with making a ingame team payment script for my gui

G’day

What I am making: I am making a payday system for a game of mine.

I kind of need help with making a script that works for paying people on certain teams a certain amount of in-game cash. I have made the GUI but I don’t know what to do for the script. I also have looked online and in the roblox studio toolbox and I can’t find anything that helps.

Below I have attached an image of what the GUI looks like so you get the idea

1 Like

Let me know if I have put it in the wrong category.

1 Like

what you need to to is get the players team (player.Team) and set a value of how much they should be payed

1 Like

What was this post? it appeared then disappeared on me

1 Like

I wrote a comment on how to tackle this issue but I completely messed up the code.

Are they getting payed in intervals or after they do a certain task?

Script in ServerScriptService:

game.Players.PlayerAdded:Connect(function(player)
    player:GetPropertySignalChanged("Team"):Connect(function()
        if player.Team == game.Teams.PayTeam then --change payteam with the name of your team
            --here give money
        end
    end)
end)
1 Like

I think it will be kind of both

Okay, I haven’t tested this extensively but this should be a mediocre base using @NinjaFurfante07 's example,

local Teams = { -- List of teams
	"Team1",
	"Team2",
	"Team3"
}

local Payments = { -- Payments depending on team
	["Team1"] = 100,
	["Team2"] = 200,
	["Team3"] = 300
}

local PayEvent = game:GetService("ReplicatedStorage"):WaitForChild("Event") -- Event you use to pay players

game.Players.PlayerAdded:Connect(function(player)
	player:GetPropertySignalChanged("Team"):Connect(function()
		for _,v in pairs(Teams) do -- Going through all teams to see if the players team matches
			if player.Team == v then -- If it matches then,
				local Pay = Payments[player.Team] -- Gets the pay matching the team
				PayEvent.OnServerEvent:Connect(function() -- Once the pay event is fired it will pay the player the specified amount
					player.leaderstats.Money += Pay -- Change the leaderstats.money to whatever suits your needs
				end)
			end
		end
	end)
end)

Would it be something like this?

game.Players.PlayerAdded:Connect(function(player)
player:GetPropertySignalChanged(“Team”):Connect(function()
if player.Team == game.Teams.Police then --change payteam with the name of your team

		while true do
			for _, v in pairs(game.Players:GetPlayers()) do
				v.leaderstats.Cash.Value = v.leaderstats.Cash.Value + 10
			end
			wait(5)
		end

		
	end
end)

end)

Yes but with the for loop you will give money to everyone in the game.

game.Players.PlayerAdded:Connect(function(player)
    player:GetPropertySignalChanged("Team"):Connect(function()
        if player.Team == game.Teams.Police then
            while true do
                player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 10
                wait(5)
            end
        end
    end)
end)

If you want to give money to everyone if just a player is in a team then:

game.Players.PlayerAdded:Connect(function(player)
    player:GetPropertySignalChanged("Team"):Connect(function()
        if player.Team == game.Teams.Police then
            while true do
                for _, players in pairs(game.Players:GetPlayers()) do
                    player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 10
                end
                wait(5)
            end
        end
    end)
end)

Do I insert a separate leaderboard or do I write one in with this code?

Either works, the name just has to be leaderstats and be parented to the player.

The money doesn’t appear to update on the leaderstats and it stays as the default number

Make sure that it is done on a Script

Are you using a server script or a local script? If you’re using a local script, it will not update for the server when paying.

1 Like

I put it in the standard script

@BobSutherland this is how it should be done:

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"

    local cash = Instance.new("IntValue", player)
    cash.Name = "Cash"
    cash.Value = 0

    player:GetPropertySignalChanged("Team"):Connect(function()
        if player.Team == game.Teams.Police then
            while true do
                for _, players in pairs(game.Players:GetPlayers()) do
                    player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 10
                end
                wait(5)
            end
        end
    end)
end)

And put that script in ServerSriptService if it ins’t yet.