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

My Value is not a valid member of my script?

I put the Value "Ammo" inside of the script as a child. When I run the script, it says it's not a valid member. Why is this happening?

local player = game.Players.LocalPlayer
local humanoid = script.Parent:FindFirstChild("Humanoid")
local ammo = script.Ammo

local barrel = humanoid.Parent.AnimPistol.Barrel
local grip = humanoid.Parent.AnimPistol.GAssembly.Grip
local trigger = humanoid.Parent.AnimPistol.GAssembly.Trigger

local canShoot = false
local coolDown = true
local keyBind = "f"

local mouse = player:GetMouse()

mouse.KeyDown:Connect(function(key)
	
	if key == keyBind then
		
		if ammo.Value ~= 0 and coolDown == true then
			
			canShoot = true
			
		end
		
		if canShoot == true then
			
			barrel.Transparency = 0
			grip.Transparency = 0
			trigger.Transparency = 0
			
			wait(.5)
			
			local animation = humanoid:LoadAnimation(script.Animation)
			animation:Play()
			
			wait(animation.Length)
			
			barrel.Transparency = 1
			grip.Transparency = 1
			trigger.Transparency = 1
			
			ammo.Value -= 1
			
			canShoot = false
			coolDown = false
			wait(60)
			coolDown = true
			
		end
		
	end
	
end)

1 comment

0

Try WaitForChild or a script may be destroying it

1 answer

  • Accredited to CoolBlueJay000 -

Replace line 03 with

local ammo = script:WaitForChild("Ammo")

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