Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I access game.Players within the function?

Asked by
painzx3 43
9 years ago

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

Log in to vote
0
Answered by 9 years ago

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.

0
I did as you said and closed off that conditional but no errors occur and yet the magazines do not replenish. painzx3 43 — 9y
0
Try directly changing MagazinesCarried instead of ammo? FearMeIAmLag 1161 — 9y
0
I didn't think of that but I actually don't know how to. Is like MagazinesCarried = 1 + 1? painzx3 43 — 9y
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 painzx3 43 — 9y
0
If you want to add 1 to a variable, you would do X = X + 1 FearMeIAmLag 1161 — 9y
Ad

Answer this question