Alright so, what I'm doing is creating a script where when you touch an object, (named trash), it will disappear and give you 1 point for the trash leader stat, the issue is, the trash leader stat claims its not a global variable, which it is, because there is no local with it. Here is the trash block script:
local trashblock = script.Parent
local harvest = script.Parent.harvest
trashblock.Touched:Connect(function()
if harvest == true then
trashblock.Transparency = 1
trashblock.CanCollide = false
if trashblock.Transparency == 1 then
harvest = false
end
if harvest == true then
trash.Value = trash.Value + 1
end
wait(30)
trashblock.Transparency = 0
trashblock.CanCollide = true
end
end)
And here is the leader stat (and datastore for the trash leader stat) script:
local ds = game:GetService("DataStoreService")
local trash = ds:GetDataStore("TrashStats")
game.Players.PlayerAdded:Connect(function(plr)
local ls = Instance.new("Folder")
ls.Name = "leaderstats"
ls.Parent = plr
trash = Instance.new("IntValue")
trash.Name = "Trash"
trash.Value = trash:GetAsync(plr.UserId) or 0
trash.Parent = ls
end)
Does anybody know how to fix the error? The error reads: W001: Unknown global 'trash' (the error is for the trash.Value's in the trash block script). I have literally no idea how to make it work, as it should work because in my leader stats script the trash variable is global. Any help?

2 comments
first of all, the one mistake everyone do, is not wrapping getAsync and setasync in a pcall
what is "trash.Value" in the trashblock script