My StarterPack tools are breaking after death. What is happening? How can I fix it?
Asked by
5 years ago Edited 5 years ago
I inserted a couple of custom guns I made into the StarterPack
, then tested. It worked fine, but when I reseted, the guns broke.
The animations still exist within the tool, but the script keeps saying:
(animationName) is not a valid member of Tool
I'm so confused. How can I fix this? How can I prevent this from happening?
Here is the portion of the script, defining the animations:
1 | local Equip = character:WaitForChild( 'Humanoid' ):LoadAnimation(script.Parent.Equip) |
2 | local Idle = character:WaitForChild( 'Humanoid' ):LoadAnimation(script.Parent.Idle) |
3 | local Reload = character:WaitForChild( 'Humanoid' ):LoadAnimation(script.Parent.Reload) |
4 | local Fire = character:WaitForChild( 'Humanoid' ):LoadAnimation(script.Parent.Fire) |
Here's the other portion of the script, playing the animations: (yes, its long.)
001 | local UIS = game:GetService( "UserInputService" ) |
003 | local camera = workspace.CurrentCamera |
005 | local PlayerGui = game.Players.LocalPlayer.PlayerGui |
007 | local AmmoGui = PlayerGui:WaitForChild( "CHX2Gui" ) |
008 | local currentAmmo = AmmoGui.CurrentAmmo |
009 | local maxAmmo = AmmoGui.MaxAmmo |
011 | local mouse = game.Players.LocalPlayer:GetMouse() |
013 | local backgroundFrame = AmmoGui.BackgroundFrame |
014 | local realFrame = AmmoGui.BackgroundFrame.RealFrame |
020 | local player = game.Players.LocalPlayer or game.Players.PlayerAdded |
021 | local character = player.Character or player.CharacterAdded:Wait() |
022 | while not character do |
023 | character.AncestryChanged:Wait() |
026 | local Equip = character:WaitForChild( 'Humanoid' ):LoadAnimation(script.Parent.Equip) |
027 | local Idle = character:WaitForChild( 'Humanoid' ):LoadAnimation(script.Parent.Idle) |
028 | local Reload = character:WaitForChild( 'Humanoid' ):LoadAnimation(script.Parent.Reload) |
029 | local Fire = character:WaitForChild( 'Humanoid' ):LoadAnimation(script.Parent.Fire) |
031 | local CanParticle = true |
033 | local equipped = false |
035 | local IsReloading = false |
037 | local mouse = game.Players.LocalPlayer:GetMouse() |
039 | local enableMouse = true |
041 | UIS.InputBegan:Connect( function (keyCode) |
042 | if keyCode.keyCode = = Enum.KeyCode.R then |
043 | if equipped = = true then |
044 | if IsReloading = = false then |
047 | script.Parent.Handle.Ammo.Transparency = 1 |
048 | script.Parent.Handle.PowerPart.Transparency = 1 |
051 | backgroundFrame.ImageLabel.Visible = false |
052 | realFrame.BackgroundColor 3 = Color 3. fromRGB( 255 , 0 , 0 ) |
053 | script.Parent.Handle.Reload:Play() |
054 | realFrame:TweenSize(UDim 2. new( 1 , 0 , 1 , 0 ), "Out" , "Sine" ,script.Parent.Handle.Reload.TimeLength) |
055 | wait(script.Parent.Handle.Reload.TimeLength) |
056 | script.Parent.Handle.Ammo.Transparency = 0 |
057 | script.Parent.Handle.PowerPart.Transparency = 0 |
058 | realFrame.BackgroundColor 3 = Color 3. fromRGB( 0 , 170 , 255 ) |
059 | script.Parent.Handle.Fire.SoundId = readyAmmoSound |
060 | currentAmmo.Value = maxAmmo.Value |
071 | script.Parent.Activated:Connect( function () |
072 | if enableMouse = = true then |
075 | currentAmmo.Value = currentAmmo.Value - 1 |
076 | realFrame:TweenSize(UDim 2. new( 1 , 0 ,currentAmmo.Value / maxAmmo.Value), 'In' , 'Sine' ,. 1 ) |
077 | script.Parent.Handle.Fire:Play() |
078 | if CanParticle = = true then |
079 | script.Parent.Handle.Muzzle.Fire_Effect.ParticleEmitter.Enabled = true |
081 | script.Parent.Handle.Muzzle.Fire_Effect.ParticleEmitter.Enabled = false |
083 | if enableMouse = = true and currentAmmo.Value < = 0 then |
086 | script.Parent.Handle.Fire.SoundId = emptyAmmoSound |
087 | backgroundFrame.ImageLabel.Visible = true |
088 | realFrame.BackgroundColor 3 = Color 3. fromRGB( 255 , 0 , 0 ) |
089 | currentAmmo.Value = 0 |
096 | UIS.InputBegan:Connect( function (keyCode) |
097 | if keyCode.keyCode = = Enum.KeyCode.Q then |
098 | if equipped = = true then |
099 | for i = camera.FieldOfView, 60 ,- 1 do |
100 | camera.FieldOfView = i |
106 | UIS.InputBegan:Connect( function (keyCode) |
107 | if keyCode.keyCode = = Enum.KeyCode.Q then |
108 | if equipped = = true then |
109 | for i = camera.FieldOfView, 70 , 1 do |
110 | camera.FieldOfView = i |
122 | script.Parent.Equipped:Connect( function () |
124 | AmmoGui.Enabled = true |
127 | script.Parent.Handle.Bolt:Play() |
134 | script.Parent.Unequipped:Connect( function () |
136 | AmmoGui.Enabled = false |
Sorry if the second script is long. This is all in a LocalScript
inside of the tool.