Untitled
unknown
plain_text
7 months ago
2.3 kB
5
Indexable
local runService = game:GetService("RunService")
local tool = script.Parent
local handle = tool.Handle
local spraySound = handle.SpraySound
local sprayParticle = handle.Nozzle.SprayParticle
local shooting = false
local shootTimer = 0
local player
script.Parent.Equipped:Connect(function()
local found = game:GetService("Players"):GetPlayerFromCharacter(tool.Parent)
if found ~= nil then
player = found
end
end)
script.Start.OnServerEvent:Connect(function(sender)
if sender == player then
shooting = true
spraySound.TimePosition = 0
spraySound:Play()
sprayParticle.Enabled = true
shootTimer = 0
end
end)
script.Stop.OnServerEvent:Connect(function(sender)
if sender == player then
shooting = false
spraySound.TimePosition = 2.6
sprayParticle.Enabled = false
local nozzle = handle.Nozzle
local newNozzle = nozzle:Clone()
newNozzle.Parent = handle
nozzle.Parent = workspace.Terrain
nozzle.Position = Vector3.new(0,-10000,0)
sprayParticle = newNozzle.SprayParticle
game:GetService("Debris"):AddItem(nozzle, 5)
end
end)
local baseHitbox = Instance.new("Part")
baseHitbox.Size = Vector3.new(2,2,2)
baseHitbox.BrickColor = BrickColor.new("Mid gray")
baseHitbox.Shape = Enum.PartType.Ball
baseHitbox.CanCollide = false
baseHitbox.Transparency = 1
baseHitbox.Name = "CO2"
local hitboxVelocity = Instance.new("BodyVelocity")
hitboxVelocity.P = 1000
hitboxVelocity.Velocity = Vector3.new()
hitboxVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
hitboxVelocity.Name = "BodyVelocity"
hitboxVelocity.Parent = baseHitbox
runService.Heartbeat:Connect(function(t)
if shooting then
shootTimer += t
if shootTimer > 0.5 then
shootTimer -= 0.5
local offset = Vector3.new(
(math.random() - 0.5) * 5,
(math.random() - 0.5) * 5,
(math.random() - 0.5) * 5
)
local newHitbox = baseHitbox:Clone()
newHitbox.BodyVelocity.Velocity = tool.Handle.CFrame.RightVector * 20 + offset
newHitbox.Position = handle.Nozzle.WorldPosition
newHitbox.Parent = tool.Parent
game:GetService("Debris"):AddItem(newHitbox, 2)
if shootTimer > 0.5 then
shootTimer = 0
end
end
if spraySound.TimePosition > 2.3 then
spraySound.TimePosition = 0.5
end
end
end)Editor is loading...
Leave a Comment