Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I access game.Players within the function?

I tried calling a function which would add to the "MagazinesCarried" of the gun's script however, the script does not rely on separate values that are in the tool. Instead it uses this

local MagazinesCarried = 1

That starts out the gun with one mag but I have a means of storage/collection in which players can retrieve and relocate a magazine which is actually a stringvalue named "DMRMag". The function I mentioned earlier is supposed to check the player's backpack for that stringvalue and add 1 to the current 'MagazinesCarried' . The code below is the actual function

function magUp()
local ammo = MagazinesCarried
local mag = tool.Parent.Backpack:FindFirstChild("DMRMag") --I have to go into game.Players.'WhoeverIsUsingTheGun'.Backpack but I lack the knowledge to do that. Help?
	if mag == true then
		if ammo >= 1 then
			ammo = 1 + 1
			mag:remove()
		end~

1 answer

✓ Accepted answer

You have to add an end after end~ and remove the extra symbol. You need to close off the conditional that you started on line 4.

5 comments

0

I did as you said and closed off that conditional but no errors occur and yet the magazines do not replenish.

0

Try directly changing MagazinesCarried instead of ammo?

0

I didn't think of that but I actually don't know how to. Is like MagazinesCarried = 1 + 1?

0

Oh I forgot to add in, the stringvalue which is the supposed "magazine" is actually in the player backpack so I would have to access the Player service

0

If you want to add 1 to a variable, you would do X = X + 1

This discussion is preserved as it was. New answers, comments, and votes are closed.