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

Help with a line of code?

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.

1 comment

0

NOTE* This is inside of a serverscript

1 answer

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.

1 comment

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?

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