Gun System Issue

Hey, I have a issue with my gun system where Normal mode doesn’t work on a certain team. My gun system has multiple modes which go from Normal, Team Kill, Tase, and Heal. All works except Normal, and normal works on other teams but the main group team.

Heres the error I am getting.

1 Like

This is when I am on “The Aveda Empire” team. (Photo doesn’t show cause I just switched off of it.)

1 Like

Error code you’re getting means you’re providing a nil value in a field/parameter where you’re supposed to provide a table value. Check your variables to find out why the table (assuming you’re attempting to provide one) is nil.

2 Likes

So this refers to a module script (the table) to find if the player is or is not the same team. I am not the best with nil values. After it finds out it would change the mouse icon. (In around 30 minutes I can get you some pictures of the code itself.

2 Likes

Here you go, from line 301 is where it seems to say where the error is. I am also giving you the table of where the teams are kept.

The line 301 script is inside the gun, while the table is in replicated storage. “allys” is the funtion for the table.


table for teams

Alright well based on this:

It seems that you want to call allys instead of referencing a value in it. Square brackets are used to descend arrays (ex: Table[Key1][Key2] or workspace["Model"]["Part"] ) while parenthesis are used to call functions and pass parameters, among other things. (ex: Function(Param1,Param2) )

Just swap out your brackets for parenthesis ^-^

If that advice isn’t needed and/or I’m misunderstanding your description, You can access values in a modulescript like so:

local ModuleScript = require(MODULE_SCRIPT)
print( ModuleScript.Templars ) -- Direct Access
print( ModuleScript["Templars"] ) -- Direct Access
print( ModuleScript[NAME_VARIABLE] ) -- Access through variable

(no table.Find needed)

1 Like

So what your saying is.

if allys(player.Team.Name, target.Team.Name) then
So on

If allys is a function then yes, if allys is supposed to be a table then make sure you’re initializing the table correctly and accessing it’s elements properly

How would initilize the table. Since allys refers to the table.

1 Like

allys thing

1 Like

Seems like you’re initializing right, so accessing is probably where the problem’s at. What’s the value of player.Team.Name?

player.Team.Name value depends on what team the player is on. So if the player qas on Civilians the name would = Civilians.

1 Like

What does the rs.ally_teams module look like?

Somehow, someway, the allys[player.Team.Name] is returning nil, I don’t think there’s enough info given to tell you what the problem is but if you know debugging then it shouldn’t be too difficult to figure out, the biggest possibility is that the team name and table key don’t match one another

1 Like