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
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)
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)
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)
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)
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)