Tool.Equipped doesn't work on this tool meaning the tool animations will play if a keybind is triggered with any other tool

I have this emoting tool script.
I tried the tool.equipped function but the animations wouldn’t work and the keybinds that triggers the tool wouldn’t work. It doesn’t even send a error.

When I remove that function, the animations are played when the emote keybind is triggered, but that keybind trigger will also play the animation on any other tool or even without tools.

local anim = game.ReplicatedStorage.Celebrations:FindFirstChild(script.Name)
local owns = false

local t1 = TweenInfo.new(0.8, Enum.EasingStyle.Quint, Enum.EasingDirection.Out)
local Indicator = game.Players.LocalPlayer.PlayerGui:WaitForChild("Start"):FindFirstChild("EmoteIndicator")

local tin = game:GetService("TweenService"):Create(Indicator, t1, {TextTransparency = 0})
local tout = game:GetService("TweenService"):Create(Indicator, t1, {TextTransparency = 1})

local MP = game:GetService("MarketplaceService")
local pass = 247391753

local tb = {261745997, 128631812, 131504927, 3777935388}

local Player = game.Players.LocalPlayer
if MP:UserOwnsGamePassAsync(Player.UserId, pass) then
	owns = true
end

if table.find(tb, Player.UserId) then
	owns = true
end

local GetData = Player:WaitForChild("Keybinds"):FindFirstChild("Celebrations"):FindFirstChild(script.Name).Value
local char = Player.Character or Player.CharacterAdded:Wait()

local UIS = game:GetService("UserInputService")

local humanoid = char:WaitForChild("Humanoid")
local animator = humanoid:FindFirstChildOfClass("Animator")
local track = animator:LoadAnimation(anim)

UIS.InputBegan:Connect(function(input, gameProcessed)
	if gameProcessed then return end
	if owns	== false then return end
	if input.KeyCode == Enum.KeyCode[GetData] then
		Player.Character.Humanoid.WalkSpeed = 0
		track:Play()
		tin:Play()
		Indicator.Text = script.Name
	end
end)

UIS.InputEnded:Connect(function(input, gameProcessed)
	if gameProcessed then return end
	if owns == false then return end
	if input.KeyCode == Enum.KeyCode[GetData] then
		Player.Character.Humanoid.WalkSpeed = 20
		track:Stop()
		tout:Play()
		Indicator.Text = script.Name
	end
end)

I’m a little unsure about what all may be going on here, but I have a few ideas.

For .Equipped: Your tool’s RequiresHandle property might still be set to true. If RequiresHandle is set to true and the tool doesn’t have a Handle, then .Equipped() will not fire.

For UIS triggering on other tools: LocalScripts in tools start right as the tool is parented to the player’s character or backpack, so UIS connections can be made and operate without the tool ever being equipped. This means you need to check if the tool is actually equipped.

local Equipped = false

script.Parent.Equipped:Connect(function() Equipped = true end)
script.Parent.Unequipped:Connect(function() Equipped = false end)

game:GetService("UserInputService").InputBegan:Connect(function(input)
	if not Equipped then return end --// Stop the code from running if the tool is not equipped
	print(input.KeyCode) 
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.