--module script
local peashooter = {}
local globalBullet = nil
local ps = game:GetService("PhysicsService")
function peashooter:Shoot(mouseHit,char)
if char:IsA("Model") then
char.Humanoid.WalkSpeed = 8
char.Humanoid.Animator:LoadAnimation(char.Shoot):Play()
local bulletsFolder = game.ReplicatedStorage.WeaponBullets
local bullet = bulletsFolder:FindFirstChild("PeashooterBullet")
local ts = game.TweenService
local ti = TweenInfo.new(0.5,Enum.EasingStyle.Quint,Enum.EasingDirection.InOut,0,false,0)
if bullet then
local newBullet = bullet:Clone()
local attachment = char.FingerGun.PistolOut.BulletAttachment
attachment.ParticleEmitter.Color = ColorSequence.new({ColorSequenceKeypoint.new(0,Color3.fromRGB(255,255,255)),ColorSequenceKeypoint.new(0.393,Color3.fromRGB(222,222,222)),ColorSequenceKeypoint.new(0.692,Color3.fromRGB(100,100,100)),ColorSequenceKeypoint.new(1,Color3.fromRGB(255,255,255))})
attachment.ParticleEmitter:Emit(1)
local origin = attachment.WorldCFrame
local originPos = attachment.WorldPosition
local target = mouseHit
local targetPos = mouseHit.Position
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {char}
params.IgnoreWater = true -- keep true for now
char.PrimaryPart.CFrame = CFrame.lookAt(char.PrimaryPart.Position,targetPos)
local direction = originPos - targetPos
local tween = ts:Create(newBullet,ti,{Position = targetPos})
newBullet:PivotTo(CFrame.lookAt(originPos,targetPos))
newBullet.Parent = workspace
task.wait(0.01)
newBullet.Anchored = false
tween:Play()
newBullet.Touched:Connect(peashooter.Touched)
local chosenSound = newBullet:FindFirstChildWhichIsA("SoundGroup"):GetChildren()[math.random(1,#newBullet:FindFirstChildWhichIsA("SoundGroup"):GetChildren())]:Clone()
chosenSound.Parent = newBullet
chosenSound:Play()
tween.Completed:Wait()
tween:Destroy()
--[[local result = workspace:Raycast(origin,direction,params)
if result then
local beam = Instance.new("Beam")
local attachment0 = script.Parent.Parent.FingerGun.PistolOut.BulletAttachment
newBullet.Position = target
local attachment1 = Instance.new("Attachment",newBullet)
beam.Attachment0 = attachment0
beam.Attachment1 = attachment1
beam.Parent = script.Parent.Parent
beam.TextureLength = result.Distance
print(result.Instance)
beam.Enabled = true
newBullet.Parent = workspace
game.Debris:AddItem(beam,1)
end]]
--game.Debris:AddItem(newBullet,5)
char.Humanoid.WalkSpeed = 16
end
else
--break
end
--end
end
function peashooter.Touched(hit:BasePart)
if hit:FindFirstChildWhichIsA("Humanoid") and not game.Players:GetPlayerFromCharacter(hit.Parent) then
print("touched!")
local humanoid = hit:FindFirstChildWhichIsA("Humanoid")
humanoid:TakeDamage(20)
end
end
return peashooter
–server script; caller
local mouse = script.Parent.Equipped:Wait()
local activated = false
local weapons = {“Peashooter”,“Spread”}
local weaponIndex = 1
script.Parent.RemoteEvent.OnServerEvent:Connect(function(player:Player, mouseHit:CFrame)
–activated = true
–while activated do
local char = script.Parent.Parent
local requiredModule = require(game.ServerScriptService.Weapons[weapons[weaponIndex]])
requiredModule:Shoot(mouseHit,char)
end)
game.ReplicatedStorage.Switch.OnServerEvent:Connect(function(player)
weaponIndex += 1
if weaponIndex > #weapons then
weaponIndex = 1
end
end)
– This already works to call