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)
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