Sell System Not Working (Unsolved)

Im making a sell system but when you try and sell the item or coal it just does not sell and give me money
local script:

local CoalSell = script.Parent
if game.Players.LocalPlayer.leaderstats.Coal.Value == 0 then
	CoalSell.Visible = false
else
	CoalSell.Visible = true
end
CoalSell.MouseButton1Click:Connect(function(Clicked)
	game.ReplicatedStorage.RemoteEvent:FireServer()
end)

Server Script:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(PlayerFired)
	if PlayerFired:WaitForChild("leaderstats") then
		PlayerFired.leaderstats.Cash.Value += 1
		PlayerFired.leaderstats.Coal.Value -= 1
	end
end)
1 Like

Your current scripts are set up to handle the selling of coal but may have some issues with visibility and event handling… try this and let me know if you receive any errors.

LocalScript:

local CoalSell = script.Parent
local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
local coalValue = leaderstats:WaitForChild("Coal")

local function updateVisibility()
    if coalValue.Value == 0 then
        CoalSell.Visible = false
    else
        CoalSell.Visible = true
    end
end

-- Update visibility initially and when coal value changes
updateVisibility()
coalValue:GetPropertyChangedSignal("Value"):Connect(updateVisibility)

CoalSell.MouseButton1Click:Connect(function()
    game.ReplicatedStorage.RemoteEvent:FireServer()
end)

Server Script:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
    local leaderstats = player:FindFirstChild("leaderstats")
    if leaderstats then
        local cash = leaderstats:FindFirstChild("Cash")
        local coal = leaderstats:FindFirstChild("Coal")
        if cash and coal and coal.Value > 0 then
            cash.Value = cash.Value + 1
            coal.Value = coal.Value - 1
        end
    end
end)

For some reason it never changed anything it still does not sell coal or update my cash
I cannot tell if its because roblox is down for me currently or its an issue with my script

Would you be able to send the place file?

So I cant do that however i can send you the info you need like where its located and stuff

A few things to check:

  1. You should have a script that creates the leaderstats folder and adds Cash and Coal IntValues to it when a player joins.
  2. Ensure RemoteEvent is correctly named and placed in ReplicatedStorage.
  3. Ensure the GUI button (CoalSell) is correctly referenced and placed in the player’s GUI.

Try adding print statements in both scripts to see if the functions are being called?

Alright most of those ive completed
heres the new post i made on this