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)
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