Im trying to make it to where if a Players team is not a citizen. the cash value + rate, will change (basically if a player has a Job the pay rate will increase)
This is where the pay rate is in the script while true do
** wait(2)**
** Cash.Value = Cash.Value + 1**
** end** end
Here is the script (free leaderstats script!)
local DataStoreService = game:GetService("DataStoreService")
local PlayerCash = DataStoreService:GetDataStore("PlayerCash")
function OnPlayerAdded(player)
local stats = Instance.new("Folder", player)
stats.Name = 'leaderstats'
local Cash = Instance.new("NumberValue", stats)
Cash.Name = "Money"
Cash.Value = 350000
local DataLoaded = Instance.new("BoolValue", player)
DataLoaded.Name = "CashDataLoaded"
DataLoaded.Value = false
local data
local attempts = 10
repeat
local success, err = pcall(function()
data = PlayerCash:GetAsync(player.UserId)
end)
if success then
print("Success!")
DataLoaded.Value = true
break
else
warn("Was problem with datastore! (Attempts left ", attempts, ")")
end
wait(1)
attempts = attempts - 1
until attempts <= 0
if not DataLoaded.Value then
warn("Player " .. player.Name .. "'s cash data has not been loaded!")
-- player:Kick("Couldn't load your data, try to rejoin later")
return
end
if data then
Cash.Value = data
end
while true do
wait(2)
Cash.Value = Cash.Value + 1
end
end
function OnPlayerRemoving(player)
if player:FindFirstChild("CashDataLoaded") and player.CashDataLoaded.Value == true then
local attempts = 10
repeat
local success, err = pcall(function()
PlayerCash:SetAsync(player.UserId, player.leaderstats:FindFirstChild("Money").Value)
end)
if success then
print("Success!")
break
else
warn("Was problem with datastore! (Attempts left ", attempts, ")")
end
wait(1)
attempts = attempts - 1
until attempts <= 0
if attempts <= 0 then
warn("Player " .. player.Name .. "'s cash data has not been saved!")
end
end
end
game.Players.PlayerAdded:Connect(OnPlayerAdded)
game.Players.PlayerRemoving:Connect(OnPlayerRemoving)
First, create a variable for the pay rate named something like PayRate. Now, you just want to add the PayRate to the cash amount and change the PayRate depending on the player’s team.
PayRate = 1
while true do
wait(2)
if player.Team == game.Teams.Citizen then -- Sets pay rate if player is a citizen
PayRate = 1
else
PayRate = 2 -- default job pay rate
if player.Team == game.Teams["Name of the job"] then -- Pay rate for a specific job
PayRate = 5
elseif player.Team == game.Teams["Another job"] then -- You can keep adding elseifs for specific jobs
PayRate = 10
end
end
Cash.Value = Cash.Value + PayRate
end
Seems like if all teams have the same color, they won’t be separated. This means the player will stay on one team no matter how you change it. Also, if the name is not valid here, that will result in an error:
if player.Team == game.Teams["Name of the job"] then
PayRate = 2
end
So make sure all the names in the if statements are valid and each team has a different color.
That script can be copy-pasted into your leaderstats script. Just make sure you replace the while true do part with @EVALDOL’s code. Also, put the dictionary somewhere before the loop. (or actually, you can put it in it if you want to)
I would not use repeat for getting or saving data. I rewrote that.
Add this new code Todo What you should do is then for each team add an Attribute called PayRate must be of number type.
local DataStoreService = game:GetService("DataStoreService")
local PlayerCash = DataStoreService:GetDataStore("PlayerCash")
function OnPlayerAdded(player)
local stats = Instance.new("Folder", player)
stats.Name = 'leaderstats'
local Cash = Instance.new("NumberValue", stats)
Cash.Name = "Money"
Cash.Value = 350000
local success, err = pcall(function()
local cash = PlayerCash:GetAsync(player.UserId)
if cash then
-- If not cash then this is a new player
Cash.Value = cash
end
end)
if not success then
error("Datastore GetAsync! for player: "..player.Name.. " Error Message: "..err)
end
local payRate = 1
player:GetPropertyChangedSignal("Team"):Connect(function()
-- If team changes then it gets Attribute of the new team
payRate = player.Team:GetAttribute("PayRate")
end)
while true do
wait(2)
Cash.Value = Cash.Value + payRate
end
end
function OnPlayerRemoving(player)
local success, err = pcall(function()
PlayerCash:SetAsync(player.UserId, player.leaderstats:FindFirstChild("Money").Value)
end)
if not success then
error("Datastore SetAsync! for player: "..player.Name.. " Error Message: "..err)
end
end
game.Players.PlayerAdded:Connect(OnPlayerAdded)
game.Players.PlayerRemoving:Connect(OnPlayerRemoving)
All of these methods should work, so the problem is somewhere else. Are you sure teams have a different Team.TeamColor? Also, as @gertkeno said, you could copy or screenshot the output. Maybe there is an error in the script before the loop.
All the teams have a different color, and it has access to API Services.
When the player presses the textbutton it changes the team but the payrate dosent change.
Are you changing the player’s team on the server? If not, that’s the problem. Changing it in a Local Script only changes it on the client but it will still look like you are on the selected team. To change the player’s team on the server, use a RemoteEvent.
Looking at the scroller of the output window, I would assume that not the whole output is shown in the video. Can you please screenshot/copy-paste the wholeoutput?
Are you using a RemoteEvent to change the player’s team? If yes, then you may have a problem with that script, maybe the team on the server is set to nil or doesn’t change at all. Can you show the scripts responsible for changing the player’s team?