It says that on line 9, it is unable to cast a value to the object, and i have no idea what to do about it, and also the remote event i put in immediately fires when you join the game, and i have no idea how to code it since I'm a horrible coder. Please help.
local rep = game:GetService("ReplicatedStorage") local PunchEquipped = rep.PunchEquipped local Player = game.Players.LocalPlayer local Character = Player.Character or Player.CharacterAdded:Wait() local Humanoid = Character:WaitForChild("Humanoid") local Animator = Humanoid:WaitForChild("Animator") local tool = script.Parent local Animation = "https://web.roblox.com/library/10336312893/Fist-Animation" local PlayAnim = Animator:LoadAnimation("Animation") if tool.Equipped then PunchEquipped.OnServerEvent(Animation) if Player == tool.Parent then print('Tool is equipped') Animation.AnimationPriority = Enum.AnimationPriority.Action Animation.AnimationID = "https://web.roblox.com/library/10336312893/Fist-Animation" Animation.Parent = Character PlayAnim:Play() end end
Unable to cast value to Object - Client - LocalScript:9
In line 10 you’re trying to check if Tool.Equipped
returns true, but it’s an event, not a boolean. You have to type Tool.Equipped:Connect(function()
which will run if the tool has been equipped. I also recommend making the AnimationTrack before Tool.Equipped. And use “rbxassetid://youranimationid” instead of the link of your animation from the website. So it will be from “https://web.roblox.com/library/10336312893/Fist-Animation” to “rbxassetid://10336312893“.
And wait, before I forget, run the animation in a server script so other players can see your animation. So fire the PunchEquipped to the server instead.
--Client (Local Script inside the tool) local rep = game:GetService("ReplicatedStorage") local PunchEquipped = rep.PunchEquipped local Player = game.Players.LocalPlayer local Character = Player.Character or Player.CharacterAdded:Wait() local Humanoid = Character:WaitForChild("Humanoid") local Animator = Humanoid:WaitForChild("Animator") local tool = script.Parent local AnimationId = "rbxassetid://10336312893" local Animation = Instance.new("Animation") Animation.AnimationId = AnimationId tool.Equipped:Connect(function() PunchEquipped:FireServer(Animator, Animation, "equip") end) tool.Unequipped:Connect(function() PunchEquipped:FireServer(Animator, Animation, "unequip") end) --Server (Normal Script inside the tool or ServerScriptService) local rep = game:GetService("ReplicatedStorage") local PunchEquipped = rep.PunchEquipped PunchEquipped.OnServerEvent:Connect(function(player: Player, animator: Animator, animation: Animation, toolStatus: string) for _, animTrack in pairs(animator:GetPlayingAnimationTracks()) do if animTrack.Animation.AnimationId ~= animation.AnimationId then if toolStatus:lower() == "equip" then local PlayAnim = animator:LoadAnimation(animation) repeat task.wait() until PlayAnim.Length > 0 PlayAnim:Play() end else if toolStatus:lower() == "unequip" then animTrack:Stop() end end end end)
Note: This script is untested and just a possible solution. If there are any errors or mistakes, lemme know. ;)