Player Money To Server

Hello,

I’ve recently got stuck throught this game development journey, mostly due to the lack of scripting knowledge since I just actively learned scripting about 2 - 3 months now. I’ve learned a lot but have yet to learn a lot more.

My problem is that I do not have a great idea to update the server about the players money nor obtain it in a efficient and secure way whilst being accessible by any server script in workspace.

I would appreciate some help around this problem.

1 Like

Try looking into remote events

Wouldn’t the server already know how much a player has? Why would you update the server about the player’s cash if that is where it should be updated?

The value is located under the player.

If you’re trying to create a money system, this is the most simplest it can get:

game.Players.PlayerAdded:Connect(function(player)
    
    local playerData = Instance.new("Folder", player)
    playerData.Name = "PlayerData"
    local dataMoney = Instance.new("IntValue", playerData)
    dataMoney.Name = "Money"
    dataMoney.Value = 0
    
end)

--[[
For console:
game.Players["username"].PlayerData.Money.Value = 100000
--]]

Just create a variable in the player, simple.

I do have a money system, but heres the thing, I’m using output to increase the players money by 2500 but it does not register that on the remotefunction however if you click on a part that increases the players money than that does register.

Example:

This right here is printed by the server before making any changes to the money
image
187.19 Is players money, 70.9 is the cost for a upgrade purchase.

The upgrade is success but yet the script does not apply the cost on to the players money. << Thats first problem

Code:

Remotefunction.OnServerInvoke = function(Player, Cost)
	
	local PlayerMoney = Player.leaderstats.Aureus.Value
	
	print(PlayerMoney, Cost)
	
	if Cost == PriceOfMid then
		if PlayerMoney > PriceOfMid then
			
			PlayerMoney -= PriceOfMid
			
			Parent.Signals.Entry.Value = false
			Parent.Signals.Mid.Value = true
			
			Purchased()
			
			NextUpgrade.Value = "High"
			
			PriceGui.Text = PriceOfHigh
			
		else
			Declined()
		end
		
	elseif Cost == PriceOfHigh then
		if PlayerMoney > PriceOfHigh then
			
			PlayerMoney -= PriceOfHigh
			
			Parent.Signals.Mid.Value = false
			Parent.Signals.High.Value = true
			
			Purchased()
			
			NextUpgrade.Value = "Deluxe"
			
			PriceGui.Text = PriceOfDeluxe
			
		else
			Declined()
		end
		
	elseif Cost == PriceOfDeluxe then
		if PlayerMoney > PriceOfDeluxe then
			
			PlayerMoney -= PriceOfDeluxe
			
			Parent.Signals.High.Value = false
			Parent.Signals.Deluxe.Value = true
			
			Purchased()
			
			NextUpgrade.Value = "Nil"
			
		else
			Declined()
		end
		
	end
end

Other problem is that any changes made with the output is not registered on the remotefunction.

Example:

the players money is 187.19 before picking up the coins on the floor in game.
image
after picking up it does register it 202.19. How ever if I hade done

game.players.Lokispades.leaderstats.Aureus.Value = 2500 // This would register for the server but not for the remotefunction even after activating it. << Thats second problem

This is the issue.

1 Like

This is the true issue, but I was so confused and frustrated so decided its better to ask people for a better system if there now was which doesn’t seem like.

The problem is your using .Value in the PlayerMoney variable. That’s only a number, so it cant be updated (I think). The solution is removing the .Value part, and then when your going to set it or use it, add .Value to it.

Updated script: (i might have forgot a few .Value so check everything out if it doesnt work.)

Remotefunction.OnServerInvoke = function(Player, Cost)
	
	local PlayerMoney = Player.leaderstats.Aureus
	
	print(PlayerMoney.Value, Cost)
	
	if Cost == PriceOfMid then
		if PlayerMoney.Value > PriceOfMid then
			
			PlayerMoney.Value -= PriceOfMid
			
			Parent.Signals.Entry.Value = false
			Parent.Signals.Mid.Value = true
			
			Purchased()
			
			NextUpgrade.Value = "High"
			
			PriceGui.Text = PriceOfHigh
			
		else
			Declined()
		end
		
	elseif Cost == PriceOfHigh then
		if PlayerMoney.Value > PriceOfHigh then
			
			PlayerMoney.Value -= PriceOfHigh
			
			Parent.Signals.Mid.Value = false
			Parent.Signals.High.Value = true
			
			Purchased()
			
			NextUpgrade.Value = "Deluxe"
			
			PriceGui.Text = PriceOfDeluxe
			
		else
			Declined()
		end
		
	elseif Cost == PriceOfDeluxe then
		if PlayerMoney.Value > PriceOfDeluxe then
			
			PlayerMoney.Value -= PriceOfDeluxe
			
			Parent.Signals.High.Value = false
			Parent.Signals.Deluxe.Value = true
			
			Purchased()
			
			NextUpgrade.Value = "Nil"
			
		else
			Declined()
		end
		
	end
end

Also, another thing to note is you are sending the cost with a remote event. This is highly exploitable and not recommended. An exploiter could set the cost to 0 and get the item for free.

It did fix issue 1, it now applies the cost onto the players money however issue 2 is still like that, possible that issue 2 is normal and not really a issue?

Thank you for mentioning that I’ll make sure to find a better way for the “Cost” thing.

1 Like

I believe its normal that it does not register the values when set from output in Studio, I went in game and tried changing value from output and this time it did register it and it worked perfectly fine as it should.

Very much appriciate your help and time. :+1:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.