My pump action shotgun doesn't pump, even though I shot the gun. Why isn't it working? The only error I receive is in the event handler saying it's unable to cast value to object. Any ideas?
local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")
local Configs = Tool:WaitForChild("Settings")
local Bullets = Configs:WaitForChild("Bullets")
local MaxBullets = Configs:WaitForChild("MaxBullets")
local CoolDown = Configs:WaitForChild("CoolDown")
local Hold = Tool:WaitForChild("Hold")
local ReloadGunAnim = Tool:WaitForChild("Reload")
local PumpAnim = Tool:WaitForChild("Pump")
local PlayAnim = game.ReplicatedStorage:WaitForChild("PlayAnimation")
local StopAnim = game.ReplicatedStorage:WaitForChild("StopAnimation")
local Fire = Handle:WaitForChild("Shoot")
local Reload = Handle:WaitForChild("Reload")
local PumpSound = Handle:WaitForChild("Pump")
local Character = game:GetService("Players").LocalPlayer.Character
local Debounce = true
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Reloading = false
local Equipped = false
Tool.Equipped:Connect(function()
PlayAnim:FireServer(Hold)
Equipped = true
end)
Tool.Unequipped:Connect(function()
StopAnim:FireServer()
Equipped = false
end)
Tool.Activated:Connect(function()
if Debounce == true then
Shoot()
Debounce = false
wait(CoolDown.Value)
Debounce = true
end
end)
function Shoot()
if Bullets.Value > 0 then
for i = 10,0,-1 do
local ray = Ray.new(Tool.Handle.CFrame.p, (Mouse.Hit.p - Tool.Handle.CFrame.p + Vector3.new(math.random(-2,2), math.random(-2,2), 0)).Unit * 1000)
local part, position = workspace:FindPartOnRay(ray, Player.Character, false, true)
local beam = Instance.new("Part", workspace)
beam.BrickColor = BrickColor.new("Medium stone grey")
beam.Material = "Metal"
beam.Transparency = 0.5
beam.Anchored = true
beam.Locked = true
beam.CanCollide = false
beam.Name = "Bullet"
local distance = (Tool.Handle.CFrame.p - position).magnitude
beam.Size = Vector3.new(0.3, 0.3, distance)
beam.CFrame = CFrame.new(Tool.Handle.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
game:GetService("Debris"):AddItem(beam, 0.1)
Fire:Play()
Pump()
if part then
local humanoid = part.Parent:FindFirstChild("Humanoid")
if not humanoid then
humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
end
if humanoid then
humanoid:TakeDamage(80)
end
end
end
elseif Bullets.Value <= 0 then
ReloadGun()
Debounce = false
end
end
function Pump()
PlayAnim:FireServer(Pump)
PumpSound:Play()
Bullets.Value = Bullets.Value - 1
wait(2)
PlayAnim:FireServer(Hold)
end
function ReloadGun()
if Reloading == false and Equipped == true then
Reloading = true
PlayAnim:FireServer(ReloadGunAnim)
Reload:Play()
wait(1.4)
Bullets.Value = MaxBullets.Value
PlayAnim:FireServer(Hold)
Reloading = false
end
end
function onKeyPress(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.R then
ReloadGun()
end
end
game:GetService("UserInputService").InputBegan:connect(onKeyPress)

2 comments
What line do you get that error?
I got it at the event handler.