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

How to create a player's money check?

Asked by
Xufly 8
5 years ago

I create a tycoon. You can give me advice on how to add a player’s money check every second (that is, protection against what would be changed by some kind of script), that is, the script checks every second whether the player has any money left before. If the money exceeded to 9,999,999,999 and more, then the script immediately kicks the player from the server.

0
Xufly, while it is impossible to get that amount of money waiting, it is also impossible to get that amount of money by forcing code. Use the command bar in studio to try changing your amount to that and it will automatically make it negative. If youre using his script then you might as well not use one at all. cmgtotalyawesome 1418 — 5y

2 answers

Log in to vote
3
Answered by 5 years ago
Edited 5 years ago

Not saying the current answer isn't going to work, but it isn't a very great idea to kick a player out for having a lot of money, what you should be checking for is if the difference in their money is above a certain number. In order for this to be logical though, you would have to cap the amount of money your giver can hold (the thing you step on to receive the money). The reason for capping the max amount is because if a player sits around awhile and then collects his money, he may get kicked out of the game, even though he did nothing wrong. The code would look like this.

game.Players.PlayerAdded:Connect(function(plr)
    local GiverMaxOutput = --whatever you want the giver to stop at.
    local CurrentBalance = 0
    --make your leaderstats like before
    (variable you used for money here).Changed:Connect(function()
        if money.Value > CurrentBalance + GiverMaxOutput
            plr:Kick("Cheating")
        else
            CurrentBalance = (variable for money).Value
        end
    end)
end)

You don't have to use this, however, it would make your game much more playable, as no one can get kicked for being on a server for a long time.

Edit:

Its clear that you probably won't use this, but in case you change your mind or realize that this way is easily better and still allows the game to be playable, I decided to add the script that caps the amount in the giver. (sorry for the run on sentence lmao). I'm going to make assumptions on how you have your system set up, but if it isn't like this it should still give you an idea.

I'm not sure if you can set a max value on an IntValue using properties as I don't have access to studio currently, but I would suggest looking through properties, as that would be the easiest way. If this fails, the script below should do it.

--[[
This script should be placed inside the collector at the end of your conveyor.
]]

--// Variables \\--

MaxGiverOutput = x
CashToCollect = --(locate your value inside of the giver (make sure you only define the object                  and not the actual value))

--// Main Script \\--

script.Parent.Touched:Connect(function(hit)
    --I'm assuming you have a value inside of your object at this point
    if hit:FindFirstChild("Worth") and CashToCollect.Value ~= MaxGiverOutput then
        if CashToCollect.Value + hit.Worth.Value =< MaxGiverOutput then
            hit:Destroy()
            CashToCollect.Value = CashToCollect.Value + hit.Worth.Value
        end
    end
end)

-Cmgtotalyawesome

0
It is physically impossible to get more than 99999999, you have to wait about 10 days, and during this time the server restarts Xufly 8 — 5y
Ad
Log in to vote
-1
Answered by 5 years ago
Edited 5 years ago
maxMoneyBeforeSuspicion = 9999999998;
money = 0; --Money will increase over time from stuff, maybe the player hacking.

if (money > maxMoneyBeforeSuspicion) then
    --Code to kick a player or give a warning or confiscate money or add to blacklist or something.
end

With a setup that looks something like this, each player their own script to keep track of money and stuff.

0
Thank you so much, you helped me push my tycoon one step further into the defense. Xufly 8 — 5y
0
Glad I could help. bludud1234 40 — 5y
0
very good ;3 turtle2004 167 — 5y

Answer this question