I made a gun, and it works well. But today I tried to make it play an animation, and it would not play. It errored with an error message of: Play is not a valid member of animation. Why am I getting this error?
Here is the gun:
The following code must be a local script:
local Tool = script.Parent
local FireRate = 5 -- How many times per second it fires a bullet :P
local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()
local TakeDownRemote = Tool:WaitForChild("Shot")
local Ammo = Tool:WaitForChild("Ammo")
local ShootVal = false
local Range = 250
local D = false
local Humanoid = Player.Character:FindFirstChild("Humanoid")
local Animation = Tool:WaitForChild("Hold")
script.Parent.Equipped:Connect(function()
Humanoid:LoadAnimation(Animation)
Animation:Play()
end)
local function Shoot()
if ShootVal == true and Ammo.Value > 0 and D == false then
D = true
repeat
wait(1 / FireRate)
Ammo.Value = Ammo.Value - 1
local ray = Ray.new(Tool.ShootSlider.CFrame.p, (Mouse.Hit.p - Tool.ShootSlider.CFrame.p).unit * Range)
local part, position = workspace:FindPartOnRayWithIgnoreList(ray, {script.Parent, Player.Character}, false, false)
if part then
if part.Parent:FindFirstChild("Humanoid") then
TakeDownRemote:FireServer(part.Parent:FindFirstChild("Humanoid"))
--part.Parent:FindFirstChild("Humanoid"):TakeDamage(10)
elseif not part.Parent:FindFirstChild("Humanoid") then
if part.Parent:IsA("Accessory") then
part.Parent:Destroy()
end
end
end
until Ammo.Value <= 0 or ShootVal == false or Player.Character:FindFirstChild("Humanoid").Health <= 0
end
wait(1 / FireRate)
D = false
end
Mouse.Button1Down:Connect(function()
ShootVal = true
Shoot()
end)
Mouse.Button1Up:Connect(function()
ShootVal = false
end)