I’m using :EquipTool() to equip a tool to a player when they join my game. This works fine until I try using a costume such as the Robloxian 2.0 which causes my script to semi-break. When I try using :EquipTool() with a costume, it equips the tool but it breaks the functionality of the tool (it doesn’t execute any code).
Here is the code I’m using to equip the tool to the player:
local tools = game.ReplicatedStorage:WaitForChild("Tools")
player.CharacterAdded:Connect(function(character)
local tool = tools:WaitForChild("SwordRegion"):Clone()
tool.Parent = tools
local humanoid = character:WaitForChild("Humanoid")
humanoid:EquipTool(tool)
end)
The code I’m using for my tool is fine because my tool works if you just equip it from the backpack by pressing a number key.
The issue is your tool’s code rather than either the EquipTool function or the code you posted. Your code completely fine, any other changes to it wouldn’t change the issue and would in fact, in hindsight, make the situation worse by completing unnecessary operations.
Are you able to post the tool’s code instead? You say it’s fine when equipped normally via number keys but that doesn’t mean it may not contain the issue.
This is a snippet of the code from my sword, I don’t want to show all of my sword’s code (so people can’t steal it) but this is basically just what the Equipped event does in my sword.
local tweenService = game:GetService("TweenService")
local runService = game:GetService("RunService")
local moduleScripts = game.ReplicatedStorage:WaitForChild("ModuleScripts")
local remoteEvents = game.ReplicatedStorage:WaitForChild("RemoteEvents")
local damageEvent = remoteEvents:WaitForChild("SwordDamageEvent")
local swordModule = require(moduleScripts:WaitForChild("SwordModule"))
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local sounds = game.ReplicatedStorage:WaitForChild("Sounds")
local rotatedRegion3 = require(moduleScripts:WaitForChild("RotatedRegion3"))
local damageValues = require(moduleScripts:WaitForChild("SwordDamageValues"))
local slashSound = sounds:WaitForChild("SlashSound")
local hitSound = sounds:WaitForChild("HitSound")
local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local animations = game.ReplicatedStorage:WaitForChild("Animations")
local mouseDown = false
local swordEquipTrack = animations:WaitForChild("SwordEquip")
local swordIdleTrack = animations:WaitForChild("SwordIdle")
local swordSlash1Track = animations:WaitForChild("SwordSlash1")
local swordSlash2Track = animations:WaitForChild("SwordSlash2")
local swordSlash3Track = animations:WaitForChild("SwordSlash3")
local swordEquipAnimation = humanoid:LoadAnimation(swordEquipTrack)
local swordIdleAnimation = humanoid:LoadAnimation(swordIdleTrack)
local swordSlash1Animation = humanoid:LoadAnimation(swordSlash1Track)
local swordSlash2Animation = humanoid:LoadAnimation(swordSlash2Track)
local swordSlash3Animation = humanoid:LoadAnimation(swordSlash3Track)
local slashCounter = 0
local function playSound(sound, parent)
local clonedSound = sound:Clone()
clonedSound.PlayOnRemove = true
clonedSound.Parent = parent
clonedSound:Destroy()
end
tool.Equipped:Connect(function()
if humanoid.Health <= 0 or not humanoid then return end
swordIdleAnimation:Play()
end)
I don’t really know if you need more of my sword’s code but even after putting a print() in the Equipped event and using the :EquipTool() code I posted, it doesn’t print anything which I think is suggesting that the Equipped event is somehow not even firing when I use :EquipTool() with costumes. My sword works completely fine with the normal R15 block rig though so I really don’t know what could be wrong.
When you say that you put a print statement in the Equipped event, is it directly under it or below the humanoid check statements? Are there any infinite yields or concerning console messages that point towards your tool’s LocalScript?
I also tried reproducing this issue on a fresh baseplate and the same issue still occurs so I don’t think it’s a problem with my tool’s scripts or my game.
Have you tried seeing if the script is even running by testing print at top and after variables are established? May also try a wait() right after parenting the tool
The script does run when I try to put a print statement on top and after the variables are established but none of the events in the tool fire such as the Equipped event and Activated event.