Cloned tool from serverstorage doesn't work

I have a tool that the player will use once I give them it from ServerStorage. It works as intended perfectly when in the StarterPack. But as soon as I clone it from ServerStorage the animation doesn’t work at all.

Here’s the script in the tool:

local tool = script.Parent

local plr = game:GetService("Players").LocalPlayer
local char = plr.CharacterAdded:Wait()
local h = char:WaitForChild("Humanoid")

local spawnevent = game.ReplicatedStorage.Tools.PlaceCrate
local objectname = "MedicalCrate"
local Mouse = plr:GetMouse()

local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://7076048298"
track = h:LoadAnimation(anim)
track.Priority = Enum.AnimationPriority.Action
track.Looped = false

tool.Equipped:Connect(function()
	track:Play()
	Mouse.Button1Down:Connect(function()
		if Mouse.Target then
			if Mouse.Target.Name == "Terrain" then
				if plr:DistanceFromCharacter(Mouse.Hit.p) <= 10 and h.Health > 0 then
					script.parent.PlaceCrate:Play()
					spawnevent:FireServer(objectname,Mouse.Hit)
					track:Stop()
					tool:Destroy()
				end
			end
		end
	end)
end)

tool.Unequipped:Connect(function()
	track:Stop()
end)

Thanks.

No its not that, I am giving the player the tool from a server script that accesses ServerStorage. It works with other tools.

This is a script for the Tool. It isn’t their cloning script. They are most likely cloning from a ServerScript but it doesn’t appear to be working

It does work, it currently works with every other tool that I have it set up for.

Ohh I just re-read. The animation doesn’t work? Let me look over the script again.

Would you like the server script?

1 Like

Loading animation from Humanoid is deprecated, use Animator | Roblox Creator Documentation instead, which is inside the humanoid.

1 Like

No! I found the issue, I’m going to help you with this right now, just editing this post right now.

You’re creating the animation outside the equipped function. You’re essentially loading the characters animation but where are you even loading it? To help mitigate this issue, I highly recommend you make it so you’re loading your animation inside equipped. I’ve had an issue like this before, but you essentially write something like this

tool.Equipped:Connect(function()
    local Animation = script.Parent.Parent.Humanoid:WaitForChild("Animator"):LoadAnimation(InsertThePathOrVariableToYourAnimationHere)

Animation:Play()
end)

Also couldn’t help but notice that you created an animation, never set it’s parent.

Try putting this:

local anim = Instance.new("Animation", tool) -- replace "tool" with where ever you want the animation to go

So how would I do that? Because I’m guessing that has to be the problem.
:thinking:

Humanoid.Animator:LoadAnimation()

I’ll keep that in mind. Void said he is editing the script as he found the issue.

Just edited my post. Please look there if it seems to help you figure out the solution

It still doesn’t seem to work despite me implementing your suggested changes. :thinking:

I recommend not using the parent argument in Instance.new(), here’s why: PSA: Don't use Instance.new() with parent argument
Not attacking you just letting you know

Alright, thank you. I am going to remove the instance.new() anyway.

Oh, I’ve never known about this before! Yeah don’t use that.

@ScottishKiltBearer I’m sort of confused why Instance.new was needed anyways?

In my eyes it’s far more practical to just create the animation object yourself, reference it in a variable, then load it on the equipped function. Let me get you one of my example scripts.

-- Get the animation folder --

local AnimationFolder = script.Parent.Animations

local ArmRaiseSource = AnimationFolder.ArmRaise

-- Call the Debounce --

local db = false

script.Parent.Equipped:Connect(function()

ArmRaiseAnimation = script.Parent.Parent.Humanoid:WaitForChild("Animator"):LoadAnimation(ArmRaiseSource)

end)

Reason why I never put ArmRaiseAnimation:Play() was because I loaded on equip, then used it inside an activated function, but that didn’t matter for this example.

Also sorry if it sounded like I attacked you for using instance.new

Yeah, I just found the problem. While running the game, I noticed there was a problem creating the animation. It wasn’t even there. So I created an animation in the explorer and done it that way. Also swapped some things around like you said. The final code is this:

local tool = script.Parent

local plr = game:GetService("Players").LocalPlayer
local char = plr.Character
local h = char:WaitForChild("Humanoid")

local spawnevent = game.ReplicatedStorage.Tools.PlaceCrate
local objectname = "MedicalCrate"
local Mouse = plr:GetMouse()

tool.Equipped:Connect(function()
	local anim = script.parent.Hold
	track = h.Animator:LoadAnimation(anim)
	track:Play()
	Mouse.Button1Down:Connect(function()
		if Mouse.Target.Name == "Terrain" then
			if plr:DistanceFromCharacter(Mouse.Hit.p) <= 10 and h.Health > 0 then
				script.parent.PlaceCrate:Play()
				spawnevent:FireServer(objectname,Mouse.Hit)
				track:Stop()
				tool:Destroy()
			end
		end
	end)
end)

tool.Unequipped:Connect(function()
	track:Stop()
end)

2 Likes

This works just fine now I assume? or is there still some slight issue somewhere?

1 Like

It seems to be working perfectly.

1 Like

Thanks for your help, I learnt a thing or two.