Hey guys so i have this taser tool where the animations no longer load after the player has died and respawned or respawned in general. Please assist. I have little to no experience with lua.
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local uxpRS = ReplicatedStorage:WaitForChild("uxpRS")
local GlobalEvents = uxpRS.GlobalEvents
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
if not Player:HasAppearanceLoaded() then Player.CharacterAppearanceLoaded:Wait() end
local MouseParent = Player:GetMouse()
local uxpRS = ReplicatedStorage:WaitForChild("uxpRS")
local GlobalEvents = uxpRS:WaitForChild("GlobalEvents")
local Tool = script.Parent
local Animations = uxpRS.TaserSystem.Animations
local canUse = true
local PlayerPlayerGui = Player.PlayerGui
local GunUI = PlayerPlayerGui:WaitForChild("GunUI")
local SoundFolder = Tool.Handle.Sounds
local ToolValues = Tool.ToolValues
local Settings = Tool.Settings
local EquipAnimation = Animations.EquipAnimation
local IdleAnimation = Animations.IdleAnimation
local ReloadAnimation = Animations.ReloadAnimation
local EquipAnimationTrack = Character.Humanoid:LoadAnimation(EquipAnimation)
local IdleAnimationTrack = Character.Humanoid:LoadAnimation(IdleAnimation)
local ReloadAnimationTrack = Character.Humanoid:LoadAnimation(ReloadAnimation)
local function reloadFunction()
if ToolValues.BulletValue.Value <= 0 and ToolValues.AmmoValue.Value >= 1 and canUse then
canUse = false
ToolValues.AmmoValue.Value -= 1
ReloadAnimationTrack:Play()
GlobalEvents.RemoteEvent:FireServer("SoundEvent", SoundFolder.Reload)
GunUI.GunFrame.StatusText.Text = "Reloading..."
task.wait(2)
ToolValues.BulletValue.Value = 1
GunUI.GunFrame.BulletText.Text = ToolValues.BulletValue.Value
GunUI.GunFrame.AmmoText.Text = ToolValues.AmmoValue.Value
GunUI.GunFrame.StatusText.Text = "Ready"
canUse = true
elseif ToolValues.AmmoValue.Value <= 0 then
GlobalEvents.RemoteEvent:FireServer("SoundEvent", SoundFolder.Empty)
end
end
Tool.Equipped:Connect(function(Mouse)
Mouse.Icon = "rbxassetid://"..11538440708
task.spawn(function()
EquipAnimationTrack:Play()
task.wait(.1)
IdleAnimationTrack:Play()
end)
GunUI.GunFrame.AmmoText.Text = ToolValues.AmmoValue.Value
GunUI.GunFrame.BulletText.Text = ToolValues.BulletValue.Value
GunUI.GunFrame.Visible = true
UserInputService.InputBegan:Connect(function(input, gameProccessedEvent)
if input.KeyCode == Enum.KeyCode.R and not gameProccessedEvent then
reloadFunction()
end
end)
end)
Tool.Unequipped:Connect(function()
Tool.Handle.BeamAttachment.Beam.Attachment1 = nil
IdleAnimationTrack:Stop()
EquipAnimationTrack:Stop()
ReloadAnimationTrack:Stop()
GunUI.GunFrame.Visible = false
end)
Tool.Activated:Connect(function()
if ToolValues.BulletValue.Value >= 1 then
ToolValues.BulletValue.Value = 0
GunUI.GunFrame.BulletText.Text = ToolValues.BulletValue.Value
GlobalEvents.RemoteEvent:FireServer("SoundEvent", SoundFolder.Fire)
GunUI.GunFrame.StatusText.Text = "Empty"
GlobalEvents.RemoteEvent:FireServer("FireEvent", MouseParent.Hit.Position, Tool.Handle.Position, Tool.Handle.BeamAttachment, Tool.Handle.Sounds)
if Settings.AutoReload.Value then
canUse = false
task.wait(1)
reloadFunction()
end
else
GlobalEvents.RemoteEvent:FireServer("SoundEvent", SoundFolder.Empty)
if Settings.ClickReload.Value then
reloadFunction()
end
end
end)```
try loading the animation before it plays, like just place the loadanimation the line before it plays. if that also doesnt work, try defining the character variable everytime the anim plays
What your doing wrong here is your loading the animations once. Try this code:
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local uxpRS = ReplicatedStorage:WaitForChild("uxpRS")
local GlobalEvents = uxpRS.GlobalEvents
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
if not Player:HasAppearanceLoaded() then Player.CharacterAppearanceLoaded:Wait() end
local MouseParent = Player:GetMouse()
local uxpRS = ReplicatedStorage:WaitForChild("uxpRS")
local GlobalEvents = uxpRS:WaitForChild("GlobalEvents")
local Tool = script.Parent
local Animations = uxpRS.TaserSystem.Animations
local canUse = true
local PlayerPlayerGui = Player.PlayerGui
local GunUI = PlayerPlayerGui:WaitForChild("GunUI")
local SoundFolder = Tool.Handle.Sounds
local ToolValues = Tool.ToolValues
local Settings = Tool.Settings
local EquipAnimation = Animations.EquipAnimation
local IdleAnimation = Animations.IdleAnimation
local ReloadAnimation = Animations.ReloadAnimation
local EquipAnimationTrack = Character.Humanoid:LoadAnimation(EquipAnimation)
local IdleAnimationTrack = Character.Humanoid:LoadAnimation(IdleAnimation)
local ReloadAnimationTrack = Character.Humanoid:LoadAnimation(ReloadAnimation)
local function reloadFunction()
if ToolValues.BulletValue.Value <= 0 and ToolValues.AmmoValue.Value >= 1 and canUse then
canUse = false
ToolValues.AmmoValue.Value -= 1
ReloadAnimationTrack:Play()
GlobalEvents.RemoteEvent:FireServer("SoundEvent", SoundFolder.Reload)
GunUI.GunFrame.StatusText.Text = "Reloading..."
task.wait(2)
ToolValues.BulletValue.Value = 1
GunUI.GunFrame.BulletText.Text = ToolValues.BulletValue.Value
GunUI.GunFrame.AmmoText.Text = ToolValues.AmmoValue.Value
GunUI.GunFrame.StatusText.Text = "Ready"
canUse = true
elseif ToolValues.AmmoValue.Value <= 0 then
GlobalEvents.RemoteEvent:FireServer("SoundEvent", SoundFolder.Empty)
end
end
Tool.Equipped:Connect(function(Mouse)
EquipAnimationTrack = Character.Humanoid:LoadAnimation(EquipAnimation)
IdleAnimationTrack = Character.Humanoid:LoadAnimation(IdleAnimation)
ReloadAnimationTrack = Character.Humanoid:LoadAnimation(ReloadAnimation)
Mouse.Icon = "rbxassetid://"..11538440708
task.spawn(function()
EquipAnimationTrack:Play()
task.wait(.1)
IdleAnimationTrack:Play()
end)
GunUI.GunFrame.AmmoText.Text = ToolValues.AmmoValue.Value
GunUI.GunFrame.BulletText.Text = ToolValues.BulletValue.Value
GunUI.GunFrame.Visible = true
UserInputService.InputBegan:Connect(function(input, gameProccessedEvent)
if input.KeyCode == Enum.KeyCode.R and not gameProccessedEvent then
reloadFunction()
end
end)
end)
Tool.Unequipped:Connect(function()
Tool.Handle.BeamAttachment.Beam.Attachment1 = nil
IdleAnimationTrack:Stop()
EquipAnimationTrack:Stop()
ReloadAnimationTrack:Stop()
GunUI.GunFrame.Visible = false
end)
Tool.Activated:Connect(function()
if ToolValues.BulletValue.Value >= 1 then
ToolValues.BulletValue.Value = 0
GunUI.GunFrame.BulletText.Text = ToolValues.BulletValue.Value
GlobalEvents.RemoteEvent:FireServer("SoundEvent", SoundFolder.Fire)
GunUI.GunFrame.StatusText.Text = "Empty"
GlobalEvents.RemoteEvent:FireServer("FireEvent", MouseParent.Hit.Position, Tool.Handle.Position, Tool.Handle.BeamAttachment, Tool.Handle.Sounds)
if Settings.AutoReload.Value then
canUse = false
task.wait(1)
reloadFunction()
end
else
GlobalEvents.RemoteEvent:FireServer("SoundEvent", SoundFolder.Empty)
if Settings.ClickReload.Value then
reloadFunction()
end
end
end)```