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

My Value is not a valid member of my script?

Asked by 3 years ago

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)

0
Try WaitForChild or a script may be destroying it CoolBlueJay000 48 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
  • Accredited to CoolBlueJay000 -

Replace line 03 with

local ammo = script:WaitForChild("Ammo")
Ad

Answer this question