Tool Script does not work with custom characters

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want the script to work with my custom characters

  2. What is the issue? Include screenshots / videos if possible!
    I made a toy hammer which when equipped, kills NCPs. It works with roblox avatars but doesnt seem to work with my custom characters. I have welded the tool onto my custom characters right hand and it equips and unequips fine. Its just not calling up my slash animation etc or doing anything.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I looked on dev hub but the problems only seem to be about equipping the tool - which ive done as a weld and that works fine. My code is below. I would like some guidance on which part may not be working due to changing to a custom character - my character animations have been put into the generic Roblox Animate script and values etc- ive got all other animations working fine using this method.

-- This is an example Lua code block
local tool = script.Parent

local canDamage = false

local sound = script.Parent.BOING

local debounce = false

local function onTouch(otherPart)

wait(6)


	local humanoid = otherPart.Parent:FindFirstChild("Humanoid")



	if not otherPart or not otherPart.Parent or game.Players:GetPlayerFromCharacter(otherPart.Parent) then 
		sound:Play() 
		
		return end
	


	if humanoid.Parent ~= tool.Parent and canDamage then 
		
		sound:Play()
		
		humanoid:TakeDamage(50)

	else

		return
end
	
	if not debounce then

		debounce = true

		wait(2)
		debounce = false


	canDamage = false

end
end


local function slash()

	local str = Instance.new("StringValue")

	str.Name = "toolanim"

	str.Value = "Slash" 

	str.Parent = tool

	canDamage = true
	

end

tool.Activated:Connect(slash)

tool.Handle.Touched:Connect(onTouch)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

3 Likes

The tool animations (none, slash and lunge) are designed for R6/R15 avatars specifically, for them to be compatible with your custom rig, your custom rig will need limbs that match those of either R6 or R15.

1 Like

Thank you for your reply. My character has been rigged exactly the same except I’ve welded a joint from the tool to its hand. Could it be this weld that is stopping it from working?

2 Likes

What do you mean by rigged exactly the same? Do the limb names match?

Is your problem the tools not attaching to your custom characters? It could be because your character dosent have a RightGripAttachment in the right hand. If you look in the right hand of a normal Roblox character, you will see a RightGripAttachment.

Yes limbs and joints named the same. All of my other animations work such as run, Jump etc

I tried the right hand grip but it didn’t work so I settled to welding it as a joint. My character equips and unequips it but the script has stopped working. Is it because the script isnt recognising it as a right hand grip attachment therefore it’s classing it as unequipped?

The script may have stopped because of an error, can you screenshot the output for me?

It shows no errors in the output

Is your problem the character is not playing an attack animation?
It could be because of the default tool grip animation overriding it.

I changed the animation ID in the Roblox animation script (R15) is there no way of overriding it this way like one can with the run, jump etc animations? I managed to override the toolnone animation by putting in my own animation ID.

Would you be able to provide a recording of a custom character trying to execute the animation with the tool?

I see the problem. Your line of code here: if not otherPart or not otherPart.Parent or game.Players:GetPlayerFromCharacter(otherPart.Parent) then logically says “if the character belongs to a player”, which in this case it does “…do nothing and just ignore it”. Change it to: if not otherPart or not otherPart.Parent then to fix the problem.

I won’t be able to get on studio tonight. But you’ll only see my character equip the tool and then do nothing with it when I click the mouse button so nothing much to see apart from my character with his tool equipped.

This problem has to be something to do with letting my animation script know that my character has it equipped.

This was so that the tool didn’t destroy other players and only ncps otherwise it was killing players

But the custom character was a player. If you add a StarterCharacter, it will be linked to the player. If you want it to work, you must find a workaround.

I would recommend a value in the character, presumably called IsNotPlayer or something like that, to bypass the if statement you set up.

Sorry, There is actually an error - i thought that there wasnt when i replied to you. From my understanding - it seems it is not recognising my Character as the humanoid because there isnt a hand grip so im guessing - since i cant put a working hand grip in a custom character (tell me if im wrong), i need to let the script know that the tool is equipped and my character is the parent? The error reads as:

Workspace.Dummy.Emoji Hammer.Damage:25: attempt to index nil with ‘Parent’ - Server - Damage:25

The error is because humanoid in the variable specified is not assigned. You added a wait(6), so is the other character dying? If the character dies, the Humanoid cannot be found. If this really is the problem, you can either increase respawn time or remove the wait statement.

The character is not the humanoid. You didn’t add a statement to prevent the error. I would recommend if not humanoid then return end or something, and possibly print out some debugging data.

That shouldn’t matter at all.

So anyways, I think removing the wait statement and adding that extra error catcher might solve the problem. I did notice sound:Play() plays anyways so I’m not sure if that’s intentional, but I think the script is coded nicely. I would also replace otherPart.Parent:FindFirstChild("Humanoid") with otherPart.Parent:FindFirstChildWhichIsA("Humanoid") as it doesn’t care what the Humanoid is named.

Thankyou, ive made that change now but it still doesnt work. Ive taken the weld off to see what happens and my tool doesnt come out but my characters toolnone animation plays with no tool in my hand. Its just not detecting that im holding the tool.

I have some experience with tools, but what I’ve done to get a sword-like animation to play is renaming the Handle to handle, which gets toolnone to play. So, is your Handle named “Handle”?

Also, is RequireHandle set to false? If there is no handle (named “Handle”), this should be false.