Why am I getting an atempt nil index with leaderstats error in this script?
local button = script.Parent
local player = button:FindFirstAncestorOfClass("Player")
repeat
player = button:FindFirstAncestorOfClass("Player")
task.wait()
until player ~= nil
local debounce = true
button.MouseButton1Click:Connect(function()
if debounce then
debounce = false
local leaderstats = player:WaitForChild("leaderstats")
local Clicks = leaderstats:WaitForChild("Clicks")
Clicks.Value += 1
task.delay(0.5, function()
debounce = true
end)
end
end)
local debounce2 = true
player.PlayerGui.Shop.ShopFrame.X1dot5.MouseButton1Click:Connect(function()
local leaderstats = player:WaitForChild("leaderstats")
local Clicks = leaderstats:WaitForChild("Clicks")
local Coins = leaderstats:WaitForChild("Coins")
if (Coins.Value >= 50) and debounce2 then
debounce2 = false
Clicks.Value += 1.5
task.delay(0.5, function()
debounce2 = true
end)
end
end)
Line 27 is the issue.

2 comments
Which line?
it is likely that there is something wrong with defining player