Roblox Script Refuses add leaderstats with SaleValue

So I’m currently working on a game with a realistic work system. I’ve made a Regiestar that goes along with a selling station. How the script is supposed to work, is that, when the station has been set up, it will take the player’s username and put it on textlabel within a billboardgui. When a player comes up to the registar, equips a wallet, and then activiates a prompt within the Registar (The Script is a parent of the prompt) it will get the name of the player via the textlabel gui, and if the name is vaild it will continue. it will get a number from a NumberValue that has been set to a certain amount. The reason why I added a numbervalue is that I want to later implement the crap where u set sale numbers. Blah blah blah.

After stealing the number, it then gives that amount to the player. Basically a player goes up to the other players selling station, and activiates the proximity prompt, and then it will get the username in the textlabel, then get the sale value via numbervalue, and then give that amount to the player. Though, I’ve run into problems with scripting this crap.

Apparently when the events happen, the script refuses to run the “Cash.Value += saleValue.Value” Part. Thus getting nothing. I’ve tried several solutions, though nothing has really worked.

I’ve published my game, leaderstats are set up for my game, I’ve tried many things, nothing much has worked. It’s weird as heck why it just won’t run this section.

Could you give me some advice or help?

It also refuses to give me errors or anything alluding to that my script is broken.

local prompt = script.Parent
local saleValue = prompt:FindFirstChild("SaleValue")

prompt.Triggered:Connect(function(player)
	-- this checks if Wallet" is equipped
	local character = player.Character
	if not character then return end

	local walletEquipped = false
	for _, tool in ipairs(character:GetChildren()) do
		if tool:IsA("Tool") and tool.Name == "Wallet" then
			walletEquipped = true
			break
		end
	end
	if not walletEquipped then return end

	---gets the player's name via the sh!tty textkabelhguioeqw
	local billboardGui = script.Parent.Parent.Parent.Parent.Parent.PlrName:FindFirstChild("BillboardGui")
	if not billboardGui then return end

	local textLabel = billboardGui:FindFirstChildWhichIsA("TextLabel")
	if not textLabel then return end

	local targetUsername = textLabel.Text
	if not targetUsername or targetUsername == "" then return end

	-- this Finds target player by name
	local targetPlayer = game.Players:FindFirstChild(targetUsername)
	if not targetPlayer then return end

	-- Makes sure SaleValue exists and is a valid number
	if not saleValue or not saleValue:IsA("NumberValue") then return end
	
	-- Add SaleValue to target player's leaderstats "Cash"
	local leaderstats = targetPlayer:FindFirstChild("leaderstats")
	if not leaderstats then return end

	local Cash = leaderstats:FindFirstChild("Cash")                                                            								          -----||
	if not Cash or not Cash:IsA("NumberValue") then return end											          ---||
	----below this is the part of the script that refuses to Focking work and doesn't give me any errors or nothing. it's just the shit below this text here wont work...\/
	print("Target:", targetPlayer)
	print("Leaderstats:", leaderstats)
	print("Cash:", Cash)
	print("SaleValue:", saleValue.Value)
	if Cash then
	Cash.Value += saleValue.Value
--	cashStat.Value += 500
	script.Parent.Parent.PurchaseEffect.Enabled = true 
	print("MoneySold!")
	end
end)

Hopefully this can get fixed, because I generally have no idea why it won’t work, other than my scripting is either non-existant or I’m extremely bad at scripting.

Use a ServerScript (not LocalScript) inside of ServerScriptService aimed at the ProximityPrompt on the Workspace.

Do these prints work when you check output?

No, they apparently don’t appear in the Output Tab. I’ve also done other ways of checking if the script is running sections, like for example what You’ve just mentioned but putting prints on each block of code, up till the line of code that gives the player the amount, and everytime I’ve tested it didn’t run that section.

See. I’m going to record a video to show you what I mean. I guess that’s the only way.


I couldn’t include the recording. Sorry. But I have a screenshot to prove what I mean.
@J_Angry

Before the line if not Cash or not Cash:IsA("NumberValue") then return end, try printing out Cash, and see what it returns.

If you remove if not Cash or not Cash:IsA("NumberValue") then return end, does the script throw an error in output?

1 Like

Wait a minute. Let me come back. I’ll give ur results just give me some time.

Apparently, That didn’t give me an error, but instead, it fixed the entire script:


So U did help i guess. I wish I could say more, but it seems as if it has been fixed.

1 Like

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