Selling script not working!

Hey, I’m currently making a simulator game and I’m wondering why my selling script is not working.

The script:


If anyone could help that would be great!

can you show us the explorer? aaaa

2 Likes

Hm, I am not sure what you are doing on line 10. A more clear way to write that would be:
money.Value += selling.Value
Edit: No Idea why you are multiplying by one.

Could you show us the output, if there is any?

Sure, 1 second. I didn’t get the hole explorer last time.

You got it wrong too, it should be money.Value += selling.Value NOT money.Value =+ selling.Value

Can you show us the console? Any errors?

Oops, yeah, it was a typo, I’ll fix that right now.

1 Like

Can I see the script that injects the leaderstats value into the player?

Capture

Why are you using a local script? Change that to a normal one.

It says their’s an error with the expression ‘+=’ in the output.

Can you change the script to be normal instead of local? Local scripts only work under client services i.e. StarterPlayer, StarterGui

Can you show me the script and the console?

change it to a normal script.please


That’s not how += works, remove the = sign and the second money argument

Local scripts don’t work in parts. Use a normal script. Plus, in a local script, someone can just exploit and give themself loads of money when selling if it is local.

I have done that. Gotta write more to send

Use this code in a normal script:

-- When a player touches the parent object, their items will be sold for gold
local sellPart = script.Parent

-- Gives the player gold for each item they have
local function sellItems(playerItems, playerGold)
	-- Gives players 10 pieces of gold for each item
	local totalSell = (playerItems.Value * 10)
	playerGold.Value = playerGold.Value + totalSell
	playerItems.Value = 0
end

local function onTouch(partTouched)
	-- Looks for a Humanoid
	local character = partTouched.Parent
	local humanoid = character:FindFirstChildWhichIsA("Humanoid")
	
	-- If a humanoid is found, gets leaderstats and calls sellItems function
	if humanoid then
		-- Get the player, so changes can be made to  the player's leaderstats
		local player = game.Players:GetPlayerFromCharacter(humanoid.Parent)
		local playerStats = player:FindFirstChild("leaderstats")
		local playerItems = playerStats:FindFirstChild("Clicks")
		local playerGold = playerStats:FindFirstChild("Coins")
		-- Sells Items and then changes the player's spaces and money
		sellItems(playerItems, playerGold)
	end
end

sellPart.Touched:Connect(onTouch)
2 Likes