What I want : I want a button that when I click it, it removes a tool from my backpack and increases my "Stoks"(leaderstat value) value by 5.
What I get : The button does nothing, I have the tool in my backpack and I click on the button, nothing happens.
local button = game.Workspace.Button.Button
local Backpack = game.Players.LocalPlayer:WaitForChild("Backpack")
local leaderstats = game.Players.LocalPlayer:WaitForChild("leaderstats")
AlthosiVal = game.Workspace.Button.Button.AlthosiVal
function sellTool()
local Tools = Backpack:GetChildren()
if #Tools > 0 then
Tools[1]:Destroy()
leaderstats.Stoks.Value = leaderstats.Stoks.Value + AlthosiVal
end
end
button.ClickDetector.MouseClick:connect(sellTool)

5 comments
It still doesn't work, origianlly, I did not have a localscript I had a normal one. I fixed that and made it a local script. I also checked to see if FilteringEnabled was off, and it was. Script still doesn't work :(
My bad, I fixed the answer.
Still doesn't work, I re-edited my code. I placed the localscript into StarterPlayer.
Just toss it into StarterGui, I already tested this. Make sure your hierarchy is correct.
local Button = a part in Workspace.