Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My private GUI's give cash script is not working. What is the problem in my script?

Asked by 5 years ago
Edited 5 years ago

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.

0
Is this a LocalScript or a Script? Is your script erroring? `name.Text == "others" or "Others"` will not work as expected. BenSBk 781 — 5y
0
It is in a script. The script runs when a remote event is fired. And the script is not erroring. StrategicPlayZ 58 — 5y
0
ok, can you print v.Name? BenSBk 781 — 5y
0
I did print v.Name but it didn't print anything. StrategicPlayZ 58 — 5y
0
That's really weird BenSBk 781 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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

0
Ok I will test your code. StrategicPlayZ 58 — 5y
Ad

Answer this question