Sorry for the long code, however I dont want any misunderstandings. The only problem in this script is how the animation wont play when I click where I want to go(It still teleports me just doesnt use the animation with the error of: "Play is not a valid member of Animation "Workspace.snipperdiaper.Tool.Animation"
If anyone can help me it would be very appreciated :D
script.Parent:WaitForChild("Animation") local tool = script.Parent local Animation = tool.Animation local player = game:GetService("Players").LocalPlayer local char = player.Character or player.CharacterAdded:Wait() local humanoid = char:FindFirstChild("HumanoidRootPart") local HumanoidAn = char.Humanoid local debounce = true local mouse = player:GetMouse() mouse.Button1Down:Connect(function() if tool.Parent ~= char then return end local position = mouse.Hit.Position local AnimationTrack = HumanoidAn:LoadAnimation(Animation) local function FireServer() game:GetService("ReplicatedStorage").ClickToTeleportEvent:FireServer(position) end if debounce == true then debounce = false FireServer() Animation:Play() player.PlayerGui.ClickToTeleportGui.TextLabel.TextTransparency = 0 player.PlayerGui.ClickToTeleportGui.TextLabel.BackgroundTransparency = 0 player.PlayerGui.ClickToTeleportGui.TextLabel.Text = "CoolDown: 5" task.wait(1) player.PlayerGui.ClickToTeleportGui.TextLabel.Text = "CoolDown: 4" task.wait(1) player.PlayerGui.ClickToTeleportGui.TextLabel.Text = "CoolDown: 3" task.wait(1) player.PlayerGui.ClickToTeleportGui.TextLabel.Text = "CoolDown: 2" task.wait(1) player.PlayerGui.ClickToTeleportGui.TextLabel.Text = "CoolDown: 1" task.wait(1) player.PlayerGui.ClickToTeleportGui.TextLabel.Text = "CoolDown: 0" task.wait(1) player.PlayerGui.ClickToTeleportGui.TextLabel.TextTransparency = 1 player.PlayerGui.ClickToTeleportGui.TextLabel.BackgroundTransparency = 1 player.PlayerGui.ClickToTeleportGui.TextLabel.Text = "CoolDown: 2" debounce = true end end)
Thanks, snipperdiaper
The error tells you exactly what the problem is: Animation objects do not possess a method called "Play". AnimationTracks possess this method and they can only be obtained by using the LoadAnimation of a humanoid's animator. You've already used it (not on the Animator though, Humanoid:LoadAnimation) is deprecated) but you used the Play method on the animation itself instead of the created AnimationTrack.
Here's what it should be, and I've also adjusted other parts of the code that could've been simplified:
local Animation = script.Parent:WaitForChild("Animation") local tool = script.Parent local player = game:GetService("Players").LocalPlayer local char = player.Character or player.CharacterAdded:Wait() local hrp = char:WaitForChild("HumanoidRootPart") local humanoid = char:WaitForChild("Humanoid") local debounce = true local mouse = player:GetMouse() local AnimationTrack = Humanoid.Animator:LoadAnimation(Animation) local teleport_gui = player:WaitForChild("PlayerGui"):WaitForChild("ClickToTeleportGui") local teleport_label = teleport_gui:WaitForChild("TextLabel") local function FireServer() game:GetService("ReplicatedStorage").ClickToTeleportEvent:FireServer(position) end tool.Activated:Connect(function() local position = mouse.Hit.Position if debounce == true then debounce = false FireServer() AnimationTrack:Play() teleport_label.TextTransparency = 0 teleport_label.BackgroundTransparency = 0 teleport_label.Text = "CoolDown: 5" for i = 5, 0, -1 do teleport_label.Text = "CoolDown: " .. i task.wait(1) end teleport_label.TextTransparency = 1 teleport_label.BackgroundTransparency = 1 teleport_labelText = "CoolDown: 2" debounce = true end end)