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

Removing Money from a Player?

Asked by 6 years ago

I was trying to make a script that would remove money from a player, but the way the game is set up the money is stored in the Server Storage. When I try to do the script it has to have the name of the player so it can function, but I do not know how to get the name of the player.


storage = game.ServerStorage:WaitForChild("PlayerMoney") price = 250 name = game.Players.LocalPlayer.Name game.ReplicatedStorage.Remotes.DontHackBoi.OnServerEvent:connect(function() if storage.name.Value >= price then storage.name.Value = storage.name.Value - 250 print "Success" else print "Failed" end end)
0
Is the script in the client or server? WaddelsG 69 — 6y
0
The script is in the server Ize_Cubz 18 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

If you're trying to have money for a specific player, I wouldn't put it in ServerStorage, rather Player.leaderstats or ReplicatedStorage Also you should change the values in a server script instead of localscript If the script is a server script you can't use game.Players.LocalPlayer, by default the OnServerConnect passes the player as an argument

storage = game.ReplicatedStorage:WaitForChild("PlayerMoney")
price = 250

game.ReplicatedStorage.Remotes.DontHackBoi.OnServerEvent:connect(function(plr)
    local name = plr.Name
    local storage2 = storage:FindFirstChild(name)
    if storage2.Value >= price then
    storage2.Value = storage2.Value - 250
        print "Success"
    else
        print "Failed"
    end
end)

This should work as long as the PlayerMoney value is placed correctly in ReplicatedStorage

Ad

Answer this question