When I sell lets say coal it just does not do anything? I still can not find any solution
Local Script:
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)
2 Likes
Open the output panel or open the dev console in testing mode (F9)
Do you get a warning saying something like
Infinite yield possible on “player:FindFirstChild(“leaderstats”)”
If yes, then its possible leaderstats
doesn’t exist as a child of the player
argument.
1 Like
Nope I get no errors or warnings in the output box or the dev console
forgot to mention you’ll need to wait 10 seconds in game for the warning to appear. You’ll get the warning after FindFirstChild yields for more than 10 seconds
Still nothing i cannot tell if this is a studio bug or I am just forgetting something minor
is leaderstats defined in the server script? try removing the if leaderstats
test and look for errors there.
Still nothing in the output or the dev console
Just to confirm, the coal value > 0 and are you pressing on the coal button?
Yes the coal value is over 0 and im pressing the coal button
All the if statements are causing issues, remove the leaderstats check and cash and coal and value if statements so we can find the issue quicker.
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
local leaderstats = player:FindFirstChild("leaderstats")
local cash = leaderstats:FindFirstChild("Cash")
local coal = leaderstats:FindFirstChild("Coal")
cash.Value = cash.Value + 1
coal.Value = coal.Value - 1
end
end)
Paste this in, once we find the issue you can put back the if statements.
Also once pasting the code in, open the output and test the button and show me the error message you receive.
Did you click directly on the button
I clicked like 7 times to make sure I did
Can you add print(“WORKING”) in the RemoteEvent.OnServerEvent just to confirm.
It did not print so its probably something with the local script
Is your output correctly set?
Can you resend me your updated code.