I tried to make a script so that when the player equips the tool it would play an animation. But things didn’t go so well. When I equip the tool, I keep getting the error “Unable cast value to object”.
These are the scripts:
Local Script:
local t = script.Parent
local to = game:GetService("ReplicatedStorage").Player.Animations
function send(pl, ty, anim)
if ty == "e" and typeof(ty) == "string" then
to:InvokeServer(pl, ty, anim)
end
end
t.Equipped:Connect(function()
delay(.1, function()
local c = t.Parent
local anim = t.Anim.Idle
send(c, "e", anim)
end)
end)
Script:
local to = game:GetService("ReplicatedStorage").Player.Animations
to.OnServerInvoke = function(pl, ty, anim)
local c = pl.Character
if c then
local h = c:FindFirstChild("Humanoid")
if h then
local tr = h:LoadAnimation(anim)
tr:Play()
else
warn("Humanoid not found in player's character")
end
else
warn("Player character not found")
end
end
I tried to fix it but it still didn’t work. I checked the inspector and it says that the value of “anim” is equal to “e” and that it is a string.