So when the script is fired this needs to check if the user has enough money then if they do subtract the "cost" from the localplayer's money.Value and add "bounty" to the user who is "searchname" .

The issue is that it is not subtracting the "cost" from the localplayer, but it is adding the bounty to the other player. Everything is functional except it is acting like it skips the substracting money part.

--Check Players

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local RemoteEvents = ReplicatedStorage:WaitForChild('RemoteEvents')
local AddBountyEvent = RemoteEvents:WaitForChild('AddBounty')

AddBountyEvent.OnServerEvent:Connect(function(PlayerWhoClicked, searchname, cost)
    local PlayerInPlayers = Players:FindFirstChild ( searchname )
	--local PlayerWhoClicked = Players:FindFirstChild( PlayerWhoClicked )
	if PlayerInPlayers then
		local PlayerWhoClickedLeaderStats = PlayerWhoClicked:FindFirstChild("leaderstats")--Believe it has something to do with this.
		local PlayerInPlayersLeaderStats = PlayerInPlayers:FindFirstChild("leaderstats")
		local Money = PlayerWhoClickedLeaderStats and PlayerWhoClickedLeaderStats:FindFirstChild("Money") or false--Or this
		local Bounty = PlayerInPlayersLeaderStats and PlayerInPlayersLeaderStats:FindFirstChild("Bounty") or false
		--PlayerWhoClicked.Name ~= searchname 
		if Money then ---From here
			local HasEnough  = Money.Value >= cost
			local Difference =  cost - Money.Value
				if Bounty then 
					Bounty.Value = Bounty.Value + cost--this works
				end
				if HasEnough then
					Money.Value = Money.Value - cost--this does not
				end--To here is the problem
				
			




			else
				print ( ('%s needs %d/%d more cash to set bounty'):format(PlayerWhoClicked.Name, Difference, cost)  )
			end
		
	else 
		print ( 'username not found' )
	end
		
end)

1 comment

0

i would help if i understand what you are talking about but i dont, so what i understand is when a player has the cost and does somethng the crrency will be subtracted by the cost and he will have more bounty?