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:

local Equip = character:WaitForChild('Humanoid'):LoadAnimation(script.Parent.Equip)
local Idle = character:WaitForChild('Humanoid'):LoadAnimation(script.Parent.Idle)
local Reload = character:WaitForChild('Humanoid'):LoadAnimation(script.Parent.Reload)
local Fire = character:WaitForChild('Humanoid'):LoadAnimation(script.Parent.Fire)

Here's the other portion of the script, playing the animations: (yes, its long.)

local UIS = game:GetService("UserInputService")

local camera = workspace.CurrentCamera

local PlayerGui = game.Players.LocalPlayer.PlayerGui

local AmmoGui = PlayerGui:WaitForChild("CHX2Gui")
local currentAmmo = AmmoGui.CurrentAmmo
local maxAmmo = AmmoGui.MaxAmmo

local mouse = game.Players.LocalPlayer:GetMouse()

local backgroundFrame = AmmoGui.BackgroundFrame
local realFrame = AmmoGui.BackgroundFrame.RealFrame

local isFull = true

local emptyAmmoSound = 'rbxassetid://154255000'
local readyAmmoSound = 'rbxassetid://419268760'
local player = game.Players.LocalPlayer or game.Players.PlayerAdded
local character = player.Character or player.CharacterAdded:Wait()
while not character do
	character.AncestryChanged:Wait()
end

local Equip = character:WaitForChild('Humanoid'):LoadAnimation(script.Parent.Equip)
local Idle = character:WaitForChild('Humanoid'):LoadAnimation(script.Parent.Idle)
local Reload = character:WaitForChild('Humanoid'):LoadAnimation(script.Parent.Reload)
local Fire = character:WaitForChild('Humanoid'):LoadAnimation(script.Parent.Fire)

local CanParticle = true

local equipped = false

local IsReloading = false

local mouse = game.Players.LocalPlayer:GetMouse()

local enableMouse = true

UIS.InputBegan:Connect(function(keyCode)
	if keyCode.keyCode == Enum.KeyCode.R then
		if equipped == true then
			if IsReloading == false then
				IsReloading = true
				Reload:Play()
				script.Parent.Handle.Ammo.Transparency = 1
				script.Parent.Handle.PowerPart.Transparency = 1
				reload = false
				enableMouse = false
				backgroundFrame.ImageLabel.Visible = false
				realFrame.BackgroundColor3 = Color3.fromRGB(255,0,0)
				script.Parent.Handle.Reload:Play()
				realFrame:TweenSize(UDim2.new(1,0,1,0),"Out","Sine",script.Parent.Handle.Reload.TimeLength)
				wait(script.Parent.Handle.Reload.TimeLength)
				script.Parent.Handle.Ammo.Transparency = 0
				script.Parent.Handle.PowerPart.Transparency = 0
				realFrame.BackgroundColor3 = Color3.fromRGB(0, 170, 255)
				script.Parent.Handle.Fire.SoundId = readyAmmoSound
				currentAmmo.Value = maxAmmo.Value
				CanParticle = true
				enableMouse = true
				reload = true
				IsReloading = false
			end
		end
	end
end)


script.Parent.Activated:Connect(function()
	if enableMouse == true then
		Fire:Play()
		isFull = false
		currentAmmo.Value = currentAmmo.Value - 1
		realFrame:TweenSize(UDim2.new(1,0,currentAmmo.Value / maxAmmo.Value),'In','Sine',.1)
		script.Parent.Handle.Fire:Play()
		if CanParticle == true then
			script.Parent.Handle.Muzzle.Fire_Effect.ParticleEmitter.Enabled = true
			wait()
			script.Parent.Handle.Muzzle.Fire_Effect.ParticleEmitter.Enabled = false
		end
		if enableMouse == true and currentAmmo.Value <= 0 then
			CanParticle = false
			reload = true
			script.Parent.Handle.Fire.SoundId = emptyAmmoSound
			backgroundFrame.ImageLabel.Visible = true
			realFrame.BackgroundColor3 = Color3.fromRGB(255,0,0)
			currentAmmo.Value = 0
		end
	end
end)

--ADS part

UIS.InputBegan:Connect(function(keyCode)
	if keyCode.keyCode == Enum.KeyCode.Q then
		if equipped == true then
			for i = camera.FieldOfView,60,-1 do
				camera.FieldOfView = i
				wait()
			end
		end
	end
end)
UIS.InputBegan:Connect(function(keyCode)
	if keyCode.keyCode == Enum.KeyCode.Q then
		if equipped == true then
			for i = camera.FieldOfView,70,1 do
				camera.FieldOfView = i
				wait()
			end
		end
	end
end)

--equipped and unequipped



Idle.Looped = true
script.Parent.Equipped:Connect(function()
	mouse.Icon = 'rbxassetid://117431027'
	AmmoGui.Enabled = true
	Equip:Play()
	wait(1.25)
	script.Parent.Handle.Bolt:Play()
	wait(0.25)
	Idle:Play()
	
	equipped = true
end)

script.Parent.Unequipped:Connect(function()
	mouse.Icon = 'rbxassetid://442141180'
	AmmoGui.Enabled = false
	equipped = false
	Reload:Stop()
	Fire:Stop()
	Equip:Stop()
	Idle:Stop()
end)

Sorry if the second script is long. This is all in a LocalScript inside of the tool.

2 comments

0

Please post the script where the animation is referenced.

0

Okay.