I'm going to preface this by saying that I don't wan't any code, but rather to further my understanding about scripting.
I've been scripting for about 2 years now, and I'm starting to get serious about it. And one question that I've been asking myself is what is the difference between a local variable and a regular variable.
Regular Variables
function removeItem()
player.Backpack.Item:Destroy()
end
while true do
wait(3)
players = game.Players:GetChildren()
player = players[math.random(1,#players)]
removeItem()
end
Local Variables
function removeItem()
player.Backpack.Item:Destroy()
end
while true do
wait(3)
local players = game.Players:GetChildren()
local player = players[math.random(1,#players)]
removeItem()
end
This script works perfectly, but when I defined everything as a local variable it didn't work, and I was getting errors everywhere. Why does this work now?

1 comment
https://scriptinghelpers.org/questions/6/local-in-front-of-variables