I have a taser tool that when equipped will play an idle animation and if a certain key is pressed, it’ll play a move, and so on and so forth. However, an issue arises when you die and respawn. In this scenario, the tool stops functioning and even the print(“Tool Equipped”) in the equipped function doesn’t call in the output.
I have looked through many posts and tried changing the way I call my character since it’s replaced on death, switching locations of humanoid calls, along with changing the way I call the tool since I believe that the issue comes from one of these reasons. However, none of the solutions have worked and I’m very confused at this point as to what’s causing the issue.
Differences during testing:
I’m working on this game with a friend and we own it under a group where we upload all our animations. In studio play test and game simulation with multiple clients, everything works just fine, when you die the tool works, all functions fired, all anims played. When we team test and I die, the tool works, however when my friend dies the bug is replicated and he can no longer use the tool which I find odd. In the actual game, the bug is replicated on both of our ends, no functions fired, thus no animations played. So all I need is for the tool to work even if the player dies (which I also have tools that work on death with the same variables called the same way, another reason why I’m confused. Furthermore, I ported everything to a game made by myself and swapped all the anims and it worked there, so there’s some fundamental understanding that I’m missing here).
Here’s my code for how I call the equipped and call my character (The local script is in the tool inside StarterPack):
-- Services --
local Players = game:GetService("Players")
local ContentProvider = game:GetService("ContentProvider")
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Debris = game:GetService("Debris")
local RunService = game:GetService("RunService")
--------------
-- Variables --
local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local taserEquip = false
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local remote = ReplicatedStorage.Events.TaserRemote
---------------
-- Animations --
--All my animation IDs goes here
ContentProvider:PreloadAsync(anims)
-- Set up global tracks for later use between functions
local taserAttackTrack = nil
local idleAnimTrack = nil
local upPoseTrack = nil
local downPoseTrack = nil
local rMoveStartWalkTrack = nil
local rMoveStartRunTrack = nil
----------------
function Equipped()
print("Taser equipped")
taserEquip = true
Idle()
end
function Unequipped()
print("Taser unequipped")
taserEquip = false
Idle()
end
function Idle()
character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:FindFirstChild("Animator")
local hrp = character:FindFirstChild("HumanoidRootPart")
if hrp then
if idleAnimTrack == nil then
print("loading anim")
idleAnimTrack = animator:LoadAnimation(idleAnim)
end
print("hrp")
if taserEquip == true then
print("Playing idle")
idleAnimTrack:Play()
else
print("Stopping idle")
idleAnimTrack:Stop()
end
end
end
function Attack(input, gameProcessedEvent)
-- All my attack stuff goes here, shouldn't be relevant
end
UserInputService.InputBegan:Connect(Attack)
tool.Equipped:Connect(Equipped)
tool.Unequipped:Connect(Unequipped)
I also get no errors since the tool equipped function is never fired. The tool simply does not respond to user input or even register that it’s being equipped after death. Anything would help, I have been stuck on this for a week, hope I’m just missing something. Thanks for your time. Let me know if any other information is needed.