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

Equipped and unequipped tool function working correctly?

Asked by 2 years ago

I only want to player to play an animation when a tool in the backpack is equipped, but the animation does not play even when the tool is equipped. The script knows the tool is equipped as it prints true and false, but the animation still does not play. Code here:

local real = false
script.Parent.Equipped:Connect(function()
    local real = true
    print(real)
    script.Parent.Unequipped:Connect(function()
        local real = false
        print(real)
local LocalPlayer = game:GetService("Players").LocalPlayer
local Controls = require(LocalPlayer.PlayerScripts.PlayerModule):GetControls()
local UIS = game:GetService("UserInputService")
local character = game.Workspace:WaitForChild(game.Players.LocalPlayer.Name)
local boom = character:WaitForChild("Humanoid") :LoadAnimation(script:WaitForChild("boom"))

UIS.InputBegan:Connect(function(key,chat)
    if chat then return end
    if real == false then return end
    if key.KeyCode == Enum.KeyCode.E then
        boom:play()
        Controls:Enable(false)
            wait(2)
        Controls:Enable(true)
        end
        end)
    end)
    end)

How should I fix it?

0
What is the local real = false?? theking66hayday 841 — 2y
0
Why are all your variables inside the Tool.Equipped Connection? Kingu_Criminal 205 — 2y
0
That was the issue, the entire script was inside the .Equipped function iiFloxy 9 — 2y
0
Im not sure what that means but real = false at the start because by default real would equal true, and the player would be able to play the animation while the tool was unequipped but not while it was equipped iiFloxy 9 — 2y

2 answers

Log in to vote
0
Answered by 2 years ago

I rewrote your script to make it more organized... Don't put your variables inside connections unless you need to rewrite them

It should work now, if it doesn't that means that the animation has no ID

--VARIABLES--
local LocalPlayer = game:GetService("Players").LocalPlayer
local Controls = require(LocalPlayer.PlayerScripts.PlayerModule):GetControls()
local UIS = game:GetService("UserInputService")
local character = game.Workspace:WaitForChild(game.Players.LocalPlayer.Name)
local boom = character:WaitForChild("Humanoid") :LoadAnimation(script:WaitForChild("boom")) 

local real = false

--CONNECTIONS--
script.Parent.Equipped:Connect(function()
    local real = true
    print(real)
end)

script.Parent.Unequipped:Connect(function()
    local real = false
    print(real)
end)


UIS.InputBegan:Connect(function(key,chat)
    if chat then return end
    if real == false then return end
    if key.KeyCode == Enum.KeyCode.E then
        boom:play()
        Controls:Enable(false)
        wait(2)
        Controls:Enable(true)
    end
end)

0
this worked, the issue was I had the entire script nested inside the .Equipped function. I figured this out on my own but this should work for people having the issue in the future iiFloxy 9 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

Ok, so. This might not be the problem, but this is what might be causing it.

  • Does your tool have no part in it called Handle, so is it just basically a tool with no parts?
  • If so, have you made it so the tool does not require a handle in the properties section so the box is set to false (has no tick in it).

Tools that have it enabled to require a handle (Enabled by default.) without a part in it called 'Handle' will NOT fire a .Equipped or .Unequipped function.

0
It does, everything else works. I just need it so the animation can only play while the tool is equipped, which is the issue iiFloxy 9 — 2y

Answer this question