I do not want customers getting worker points is there a way I can script this script to assure customers don't get points?
Rank Script: game.Players.PlayerAdded:connect(function(P) repeat wait() until P:findFirstChild("leaderstats") local Rank = Instance.new("StringValue", P.leaderstats) Rank.Name = "Rank" Rank.Value = P:GetRoleInGroup(4853203)
Points every 600 seconds script: game.Players.PlayerAdded:connect(function(p) local stats = Instance.new("IntValue", p) stats.Name = "leaderstats" local money = Instance.new("IntValue", stats) money.Name = "Worker Points" money.Value = 0 while true do wait(600) money.Value = money.Value + 1 end
I have more scripts but they don't have to do with this.
game.Players.PlayerAdded:connect(function(P) repeat wait() until P:findFirstChild("leaderstats") local Rank = Instance.new("StringValue", P.leaderstats) Rank.Name = "Rank" Rank.Value = P:GetRoleInGroup(4853203) end)
I fixed this so it can be read. This part looks like it works just fine.
game.Players.PlayerAdded:connect(function(p) local stats = Instance.new("IntValue", p) stats.Name = "leaderstats" local money = Instance.new("IntValue", stats) money.Name = "Worker Points" money.Value = 0 while true do wait(600) money.Value = money.Value + 1 end end)
Now, there are a few problems I can see already.
First off, using the function :connect()
is deprecated. You should use :Connect()
instead.
You need a conditional statement to verify that the person you are giving money to is actually a worker.
game.Players.PlayerAdded:Connect(function(p) if P:GetRoleInGroup(4853203) == "Worker" then local stats = Instance.new("IntValue", p) stats.Name = "leaderstats" local money = Instance.new("IntValue", stats) money.Name = "Worker Points" money.Value = 0 while true do wait(600) money.Value = money.Value + 1 end end end)
There are 2 little things that I see. There are 2 event listeners that are listening for the same event. I think you are allowed to do this, but just to keep things consistent, I am going to combine the 2 event listeners.
game.Players.PlayerAdded:Connect(function(P) local Rank = Instance.new("StringValue", P.leaderstats) Rank.Name = "Rank" Rank.Value = P:GetRoleInGroup(4853203) if Rank.Value == "Worker" then local stats = Instance.new("IntValue", p) stats.Name = "leaderstats" local money = Instance.new("IntValue", stats) money.Name = "Worker Points" money.Value = 0 while true do wait(600) money.Value = money.Value + 1 end end end)
There is still one more thing that I want to address. The player may leave the game, and this while loop will break because the money instance no longer exists. Although this is a connection, meaning the script will still run, we can avoid having an error printed in the output just to keep things clean by checking to see if the money instance still exists.
game.Players.PlayerAdded:Connect(function(P) local Rank = Instance.new("StringValue", P.leaderstats) Rank.Name = "Rank" Rank.Value = P:GetRoleInGroup(4853203) if Rank.Value == "Worker" then local stats = Instance.new("IntValue", p) stats.Name = "leaderstats" local money = Instance.new("IntValue", stats) money.Name = "Worker Points" money.Value = 0 while true do wait(600) if money then money.Value = money.Value + 1 end end end end)
And that's the completed script. If anyone notices any errors that I've made, please point them out.