I have a code that checks the item value and play the animation respectively according to the value but everytime the player switches item (no unequip) although the item value changes, the game does not know whether the value has changed or not (just does this if item.Value == “hi” then do stuff like play anim) and if it changes it does nothing and then the past animation stays
(Posted this topic hours ago but no correct answer yet. TL;DR : Check if player switches their equipped item without unequipping it)
I think that we’d have to see your code to know what the problem with it is. However, if you’re using the default tool system, you should be able to use ContextActionService.LocalToolEquipped on the client or you can check when a Tool gets added to the player’s character.
Because you can play animations from the client, and those animations will replicate to the server, you should be able to use ContextActionService.LocalToolEquipped and ContextActionService.LocalToolUnequipped to determine animations.
I dont want it to replicate to the server. It is a viewmodel system
Here is a piece of my code
local function isHoldingTool(player)
local ch = player.Character or player.CharacterAdded:Wait()
if ch:FindFirstChildWhichIsA("Tool") then
local tool = ch:FindFirstChildWhichIsA("Tool")
hold = true
if hold == true then
if debounce == false then
item = game.ReplicatedStorage.Viewmodels.Item:WaitForChild(tool.Name):Clone()
MAINMODULE.welditem(item)
MAINMODULE.equiq(ViewModel, item)
if tool.Value.ViewModelValue.Value == "Flashlight" then
open:Play()
debounce = true
open.Stopped:Wait()
for _, v in pairs(ViewModel.RightArm:GetDescendants()) do
if v:IsA("BasePart") then
v.Transparency = 0
end
end
Hold:Play()
elseif tool.Value.ViewModelValue.Value == "Normal" then
open:Play()
debounce = true
open.Stopped:Wait()
for _, v in pairs(ViewModel.RightArm:GetDescendants()) do
if v:IsA("BasePart") then
v.Transparency = 0
end
end
Hold:Play()
end
end
end
else
hold = false
if hold == false then
if #ViewModel.RightArm:GetChildren() == 0 then
return false
else
for i, v in pairs(ViewModel.RightArm:GetChildren()) do
v:Destroy()
end
end
if debounce then
Hold:Stop()
debounce = false
end
for _, v in pairs(ViewModel.RightArm:GetDescendants()) do
if v:IsA("BasePart") then
v.Transparency = 1
end
end
end
end
I want Hold animation and Open to stop if the player switches item and then let it play other animation needed
I have to go, so I cannot finish helping you right now. But, in case anyone else is curious, how are you detecting when to call this function?
The problem could also be with your debounce. You’re checking if debounce is false before moving on to playing the animations, and you only set it back to false when an item is unequipped. So, that could contribute to your struggle.
When a player equips an item, that item is removed from their Backpack and added to their Character. Using this logic, you can determine if they were holding an item beforehand.