I am making a GUI which is only visible to me. I can give cash to any player using that GUI. This may sound weird but I am doing it to test the new items I add. I want to add a function that if I say others then every one, except me, in the server's cash value will change to the given cash value. Here is the script. It is not working. It gives cash to others but it gives it to me too.
elseif name.Text == "others" or "Others" then local children = game.Players:GetPlayers() for i,v in pairs(children) do if v.Name ~= "StrategicPlayZ" then v.leaderstats.Cash.Value = v.leaderstats.Cash.Value + value end end end
Please tell me what is the problem here and how do I fix it. Thanks!
And by the way the script does not shows any error in the output. It just gives cash to others but to also.
Explanation
I'm not entirely what the issue is but I will try to help as much as possible.
The Solution
Before I start explaining I just want to note that having a Gui that can give players money is probably not the safest feature to have in your game. It could be exploited by people who can execute scripts in your game. For this, I recommend making a chat command that runs on the server (very crucial) that would change all of that and etc.
It might help to change the for loop a little bit for this case. It way or may not work. If it doesn't leave a comment on this answer of the error message and where it was.
This might fix your code:
elseif name.Text == "others" or "Others" then local children = game.Players:GetPlayers() for i = 1, #children do if children[i].Name ~= "StrategicPlayZ" then children[i].leaderstats.Cash.Value = children[i].leaderstats.Cash.Value + value end end end
If you have any other questions or comments, just reply to this answer! :)
-Crystal