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

Help with a line of code?

Asked by 9 years ago
ammo = game.Players:FindFirstChild(player.Name):FindFirstChild('Backpack'):FindFirstChild('Tool'):FindFirstChild('Ammo')

This is my line of code. When I call it, it tells me it Attempted to index a nil value. Any help? I checked the path, and it does exist. I can't figure out this problem.

0
NOTE* This is inside of a serverscript killerkill29 35 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

Hello KillerKill! If I am correct you're looking to make a gun? I have found a solution to your problem, all it requires is a Local Script.

Here's the code:

local ammo = game.Players.LocalPlayer:FindFirstChild("Backpack"):FindFirstChild("Tool"):FindFirstChild("Ammo");

If you really badly want to have a specific player, then here's the code for that:

if game.Players:FindFirstChild("Player") then
    plr = game.Players.Player;
    local ammo = plr.Backpack:FindFirstChild("Tool"):FindFirstChild("Ammo");
    print(ammo.Value);
else
    print("Player Not here");
end

See if you can edit that code, and get what you need out of it.

Love always, Luciferic Luci.

0
The thing is, I have FilteringEnabled, which requires this script to be in a Server Script to run. Any way to do this in a server script? killerkill29 35 — 9y
Ad

Answer this question