Why are LOCAL variables carrying over between my scripts?

I’m trying to make a set of guns for my game, so I thought that it would be a good idea to simply make a template for the guns and copy paste the scripts into each gun, modifying them a bit so that they different fire rates, etc. However, the local variables (such as local magsize = 30) would carry over between 2 different guns. I was very confused, as I thought local variables were stored locally, in the scripts. Maybe I was incorrect about local variables, can someone clarify?

1 Like

If you are referencing in the LocalScripts make sure you are doing script.Parent instead of say, workspace.Part. This way each LocalScript is modifying its Parent and not another Instance it shouldn’t be.

if you are calling the function environment (setfenv()) they will get parsed to any other script

2 Likes

I dont think this is the problem, because even when I use script.Parent or workspace.Part, the local variables still carry over.

It’s pretty difficult to answer this without looking at any of the code in question.

3 Likes