this script isnt working idk why if someone can tell me where to put something. It has to work for only one team or is there easy was like do custom leaderstats or do it something else?
local DataStoreService = game:GetService("DataStoreService") local DataStore = DataStoreService:GetDataStore("ForceStats") -- Change this with a different name. local Player = game.Players
if Player.TeamColor ~= BrickColor.new("Sea green") then do
game.Players.PlayerAdded:Connect(function(Player) local Leaderstats = Instance.new("Folder", Player) Leaderstats.Name = "leaderstats" local Currency = Instance.new("IntValue", Leaderstats) Currency.Name = "Force" -- Change "Money" with your currency. Currency.Value = 1
local Data = DataStore:GetAsync(Player.UserId) if Data then Currency.Value = Data -- Change this if you have added more currencies. end
end)
if Player.TeamColor ~= BrickColor.new("Sea green") then do game.Players.PlayerRemoving:Connect(function(Player) DataStore:SetAsync(Player.UserId, Player.leaderstats.Force.Value) end) end end end
end)
I think I see the problem.
In your code, you call the local player. (game.Players.LocalPlayer
) However, you only call game.Players
It then checks if the Player is in a team, which is SeaGrean. This should be giving a error, as the players does not have a property.
If teams are given, when a player joins, you can move it to:
game.Players.PlayerAdded:Connect(function(Player) if Player.TeamColor ~= BrickColor.new("Sea green") then end)
Local player = game.Players.LocalPlayer
will also only work if its in a local script, meaning it only runs on the client.
You also do not need 'Do', if you put a then. Let me show u some examples of when to use each:
Then:
local letter = "A" if letter == "A" then print("A") end
do:
local tableofletters = {"A", "B"} for i, letter in pairs(tableofletters) do print(letter) end
As I can not see any other issues, I am going to add a important note: Local scripts, will only run on the CLIENT. [Anything you do on a local script, can not be viewed by a normal script unless you use remote events / functions.] Scripts will run on all people. When using things such as datastores, it will be best to use a normal script, as updating values with a local script, will only show it for that specific Player, and any server sided normal scripts, can not view the value you changed with a local script.
If you have any more problems, just reply to this, I will try to find the fix!
If you wish to read more on any of the things I said, I have decided to link some websites for you: DevHub - Local Scripts DevHub - Conditional Statements using if, then, else. DevHub - Loops DevHub - DataStoreService DevHub - Leaderstats