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

I am confused about "attempt to call a nil value," what does it mean?

Asked by 3 years ago

I barely know what this means, I know its a problem with tool.Activated:Connect(toolActivated) but I'm not sure how to fix it. I know I need to change "toolActivated" to something but I'm not sure what. Does anyone have an idea of what I change it to? The main issue is that this script sometimes works but half the time it says nil value and it doesn't work.

local sound = script.Parent.Handle:WaitForChild("Sound")
local beam = script.Parent.Handle.Attachment:WaitForChild("Beam")
local tool = script.Parent
local player = tool.Parent.Parent
local chargesound = script.Parent.Handle:WaitForChild("ChargeSound")

local debounce = false

repeat wait(1) until player.Character

local character = player.Character
local humanoid = character:WaitForChild("Humanoid")

-- first animation

local animation = Instance.new("Animation")
animation.Name = "Idle"
animation.Parent = script.Parent

animation.AnimationId = "http://www.roblox.com/asset/?id=" .. "5128762272"
local animtrack = humanoid:LoadAnimation(animation)

-- second animation

local animation2 = Instance.new("Animation")
animation2.Name = "Charge"
animation2.Parent = script.Parent

animation2.AnimationId = "http://www.roblox.com/asset/?id=" .. "5653045213"
local animtrack2 = humanoid:LoadAnimation(animation2)

-- action

script.Parent.Equipped:connect(function()
    animtrack2:Play()
    sound:Stop()
    beam.Enabled = false
    chargesound:Play()
    if not debounce then
        function toolActivated()
            chargesound:Stop()
            animtrack2:Stop()
            animtrack:Play()
            wait(0.2)
            sound:Play()
            beam.Enabled = true
            wait(2)
            local debounce = true
        end
    end
end)

script.Parent.Unequipped:connect(function()
    animtrack:Stop()
    sound:Stop()
    animtrack2:Stop()
    chargesound:Stop()
    wait(.1)
    sound:Stop()
    local debounce = false
end)

tool.Activated:Connect(toolActivated)
0
toolActivated is nil Leamir 3138 — 3y
0
I know but what do I change to fix that Pyro_dood 31 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

toolActivated is in another event, meaning that it doesn't exist for things outside of that event, try putting the toolActivated event outside of the event, also using :Stop() on an animation when it is not already playing does not result in an error if that's why it is not outside of the event.

Ad

Answer this question