This is a support category for asking questions about how to get something done on the Roblox websites or how to do something on Roblox applications such as Roblox Studio.
You can write your topic however you want, but you need to answer these questions:
I’m trying to make a peashooter that shoots peas at zombies but when i run the script, it animates but doesn’t do the shooting tween and fire the pea i’ve tried asking ai for help but nothing’s working help!
here’s the script:
local TweenService = game:GetService(“TweenService”)
local RunService = game:GetService(“RunService”)
local Peashooter = script.Parent
local Humanoid = Peashooter:FindFirstChildOfClass(“Humanoid”)
local Animator = Humanoid:FindFirstChildOfClass(“Animator”)
local PeaTemplate = workspace:FindFirstChild(“Pea”)
local ShootInterval = 1.5
local Damage = 20
local AnimationId = “rbxassetid://108587954936313”
local function playAnimation()
local animation = Instance.new(“Animation”)
animation.AnimationId = AnimationId
local track = Animator:LoadAnimation(animation)
track:Play()
end
local function animateHeadAndParts()
local head = Peashooter:FindFirstChild(“FakeHead”)
local hole = Peashooter:FindFirstChild(“Hole”)
local mouth = Peashooter:FindFirstChild(“Mouth”)
if head and hole and mouth then
local originalSize = head.Size
local targetSize = originalSize + Vector3.new(0, 0, originalSize.Z)
local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut)
local headTween = TweenService:Create(head, tweenInfo, {Size = targetSize})
local holeTween = TweenService:Create(hole, tweenInfo, {Size = targetSize})
local mouthTween = TweenService:Create(mouth, tweenInfo, {CFrame = mouth.CFrame * CFrame.new(0, 0, 1)})
headTween:Play()
holeTween:Play()
mouthTween:Play()
headTween.Completed:Connect(function()
local returnTween = TweenService:Create(head, tweenInfo, {Size = originalSize})
local returnHoleTween = TweenService:Create(hole, tweenInfo, {Size = originalSize})
returnTween:Play()
returnHoleTween:Play()
end)
end
end
local function shootPea()
local pea = PeaTemplate:Clone()
pea.CFrame = Peashooter.HumanoidRootPart.CFrame
pea.Parent = workspace
local direction = Peashooter.HumanoidRootPart.CFrame.LookVector
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {Peashooter}
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
local raycastResult = workspace:Raycast(pea.Position, direction * 100, raycastParams)
if raycastResult and raycastResult.Instance.Parent:FindFirstChildOfClass("Humanoid") then
local zombieHumanoid = raycastResult.Instance.Parent:FindFirstChildOfClass("Humanoid")
zombieHumanoid:TakeDamage(Damage)
animateHeadAndParts()
end
pea:Destroy()
end
local function startShooting()
while true do
playAnimation()
shootPea()
task.wait(ShootInterval)
end
end
startShooting()