Hello! So Today Im Creating a Hood/Real Life Game Basicly Like Da Hood And I Would Like To Ask a Question.
How Do I Make My Gun Slow The Player Down Everytime The Gun Fires Even When Its Auto Or Semi + Slowing The Player Down When Reloading Too
Here’s The Code
ServerMain
local maxammo = script.Parent.MaxAmmo.Value
local ammo = script.Parent.Ammo
local reloading = false
local spread = script.Parent.EDIT.Spread.Value
script.Parent.Shoot.OnServerEvent:Connect(function (plr,Target)
if plr.Character ~= nil and plr.Character.Humanoid.Health >= .1 and script.Parent.Enabled == true and reloading == false then
script.Parent.Enabled = false
local hit = false
if ammo.Value >= 1 then
ammo.Value = ammo.Value - 1
script.Parent.Handle.FireSound:Play()
for i = 1, script.Parent.EDIT.BulletsPerShot.Value do
local dist = (script.Parent.RPart.Position - Target).Magnitude
local ray = Ray.new(script.Parent.RPart.CFrame.p, (Target - script.Parent.RPart.CFrame.p + (Vector3.new(math.random(-spread,spread)/1000,math.random(-spread,spread)/1000,math.random(-spread,spread)/1000) * dist)).unit * 2000)
local part, position = workspace:FindPartOnRay(ray, plr.Character, false, true)
print(position)
print(part)
print(Target)
local beam = Instance.new("Part")
beam.Anchored = true
beam.CanCollide = false
beam.Material = "Neon"
beam.Transparency = "0.5"
beam.BrickColor = BrickColor.new("Bright yellow")
if dist >= 60 then
beam.Size = Vector3.new( 0.042, 0.001)
else
beam.Size = Vector3.new(.1,.1,dist)
end
beam.CFrame = CFrame.new(script.Parent.RPart.CFrame.p, position) * CFrame.new(0,0,-beam.Size.Z/2)
game.Debris:AddItem(beam,10)
local fx = script.Parent.FX:Clone()
fx.Dist.Value = dist
fx.Parent = beam
fx.Disabled = false
beam.Parent = workspace
script.Parent.RPart.FlashGui.Label.Rotation = math.random(1, 360)
script.Parent.RPart.FlashGui.Enabled = true
script.Parent.RPart.Flash.Enabled = true
if part ~= nil then
if part.Parent:FindFirstChild("Humanoid") then
part.Parent:FindFirstChild("Humanoid"):TakeDamage(script.Parent.EDIT.Damage.Value)
hit = true
end
end
local hole = Instance.new("Part")
hole.Size = Vector3.new(.2,.2,.2)
hole.Material = "Plastic"
hole.Anchored = true
hole.BrickColor = BrickColor.new("Black")
hole.Shape = 0
hole.CanCollide = false
hole.Position = position
hole.Transparency = 1
game.Debris:AddItem(hole, 1)
if hit == false then
hole.Parent = workspace
end
wait()
script.Parent.RPart.FlashGui.Enabled = false
script.Parent.RPart.Flash.Enabled = false
end
elseif ammo.Value <= 0 then
script.Parent.Handle.NoAmmo:Play()
end
wait(script.Parent.EDIT.Firerate.Value)
script.Parent.Enabled = true
end
end)
script.Parent.Reload.OnServerEvent:Connect(function ()
if reloading == false then
reloading = true
script.Parent.Handle.Reload:Play()
wait(script.Parent.EDIT.ReloadTime.Value)
ammo.Value = maxammo
reloading = false
end
end)
ClientMain
local held = false
local plr = game.Players.LocalPlayer
script.Parent.Equipped:Connect(function()
chr = script.Parent.Parent
end)
script.Parent.Activated:Connect(function ()
held = true
if script.Parent.Enabled == true then
script.Parent.Enabled = false
while held == true do
if script.Parent.EDIT.BurstShots.Value >= 2 then
for i = 1, script.Parent.EDIT.BurstShots.Value do
script.Parent.Shoot:FireServer(chr.Humanoid.TargetPoint)
fire:Play()
wait(script.Parent.EDIT.BurstRate.Value)
end
else
fire:Play()
script.Parent.Shoot:FireServer(chr.Humanoid.TargetPoint)
end
if script.Parent.EDIT.Auto.Value == false then
held = false
end
wait(script.Parent.EDIT.Firerate.Value + .1)
end
if script.Parent.EDIT.Auto.Value == false then
wait(script.Parent.EDIT.Firerate.Value + .1)
end
script.Parent.Enabled = true
end
end)
script.Parent.Deactivated:Connect(function()
held = false
end)
script.Parent.Equipped:Connect(function()
wait()
holdanim = chr.Humanoid:LoadAnimation(script.Parent.HoldAnim)
holdanim:Play()
rel = chr.Humanoid:LoadAnimation(script.Parent.ReloadAnim)
fire = chr.Humanoid:LoadAnimation(script.Parent.FireAnim)
end)
script.Parent.Unequipped:Connect(function()
held = false
holdanim:Stop()
fire:Stop()
rel:Stop()
end)
game.Players.LocalPlayer:GetMouse().KeyDown:connect(function(KeyPressed)
if KeyPressed == "r" and script.Parent.Parent == plr.Character then
script.Parent.Reload:FireServer()
rel:Play()
end
end)
I Really Hope You Can Help Me With This Issue.
If You Have a Solution Please Reply