Hello! So Today I Am Making a Gun Engine For My Hood/Reallife Game And I Would Like To Ask,
How Do I Make My Gun Engine Slow Down The Player When Firing ?
I’ve Tried Editing It But It Broke The Weapon, Does Anyone Have a Solution To This ?
You Can Try Editing The Code Below :
Handler
local character
local humanoid
local animator
local animate
local animate2
local equipped = false
local filterArray = {}
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
damage = 17
script.Parent.RequestFire.OnServerEvent:Connect(function(plr,targetPosition)
if script.Parent:FindFirstChild("Handle") and equipped == true then
if animate2 then
animate2:Stop()
end
animate2 = animator:LoadAnimation(script.Fire)
animate2:Play()
local spreadPosition = targetPosition + Vector3.new(math.random(-500,500)/1250,math.random(-500,500)/1250,math.random(-500,500)/1250)
local raycastResult = workspace:Raycast(
(script.Parent.Handle.CFrame * CFrame.new(-1.9,0.11,0)).Position,
(spreadPosition - (script.Parent.Handle.CFrame * CFrame.new(-1.9,0.11,0)).Position).Unit*500,
raycastParams)
if raycastResult then
local partHit = raycastResult.Instance
if partHit.Parent:FindFirstChild("Humanoid") then
if partHit.Parent.Humanoid.Health > 0 then
if partHit.Name == "Head" then
partHit.Parent.Humanoid:TakeDamage(damage*2.5)
else
partHit.Parent.Humanoid:TakeDamage(damage)
end
if partHit.Parent:FindFirstChild("Burn") == nil then
local burn = script.Burn:Clone()
burn.Parent = partHit.Parent
burn.Disabled = false
else
partHit.Parent:FindFirstChild("Burn").BurningTime.Value = partHit.Parent:FindFirstChild("Burn").BurningTime.Value + 2
end
end
elseif partHit.Parent:IsA("Accessory") then
for _, ins in pairs(partHit.Parent.Parent:GetChildren()) do
if ins:IsA("Accessory") then
table.insert(filterArray,ins)
end
end
raycastParams.FilterDescendantsInstances = filterArray
end
end
coroutine.wrap(function()
script.Parent.Handle.PointLight.Enabled = true
script.Parent.Handle.BillboardGui.Enabled = true
script.Parent.Rpart.FlashGui.Enabled = true
wait(.08)
script.Parent.Handle.PointLight.Enabled = false
script.Parent.Handle.BillboardGui.Enabled = false
script.Parent.Rpart.FlashGui.Enabled = false
end)()
local trailPart = Instance.new("Part",workspace)
trailPart.Name = "TrailPart"
trailPart.Transparency = 1
trailPart.CanCollide = false
trailPart.Anchored = true
local attachment1 = Instance.new("Attachment",trailPart)
local beam = Instance.new("Beam",trailPart)
game.Debris:AddItem(attachment1,.075)
game.Debris:AddItem(trailPart,.075)
attachment1.WorldPosition = spreadPosition
beam.Color = ColorSequence.new(Color3.fromRGB(243, 255, 8),Color3.fromRGB(251, 255, 0))
beam.LightEmission = 1
beam.LightInfluence = 0
beam.Transparency = NumberSequence.new(0,1)
beam.Attachment0 = script.Parent.Handle.BarrelAttachment
beam.Attachment1 = attachment1
beam.FaceCamera = true
beam.Width0 = 0.100
beam.Width1 = 0.100
script.Parent.Handle.Fire1.PlaybackSpeed = 1 + math.random(-100,100)/1000
script.Parent.Handle.Fire1:Play()
script.Parent.Handle.Fire2.PlaybackSpeed = 1.25 + math.random(-100,100)/250
script.Parent.Handle.Fire2:Play()
end
end)
script.Parent.Activated:Connect(function()
script.Parent.Activated:Connect(function()
for _, ins in pairs(workspace:GetChildren()) do
if ins:FindFirstChild("Humanoid") then
for _, ins2 in pairs(ins:GetChildren()) do
if ins2:IsA("Accessory") then
if table.find(filterArray,ins2) == nil then
table.insert(filterArray,ins2)
end
end
end
end
end
raycastParams.FilterDescendantsInstances = filterArray
end)
end)
script.Parent.Equipped:Connect(function()
equipped = true
character = script.Parent.Parent
if table.find(filterArray,script.Parent.Parent) == nil then
table.insert(filterArray,script.Parent.Parent)
end
if table.find(filterArray,script.Parent) == nil then
table.insert(filterArray,script.Parent)
end
raycastParams.FilterDescendantsInstances = filterArray
if character then
humanoid = character.Humanoid
if humanoid:FindFirstChild("Animator") == nil then
animator = Instance.new("Animator",humanoid)
elseif humanoid:FindFirstChild("Animator") then
animator = humanoid:FindFirstChild("Animator")
end
end
animate = animator:LoadAnimation(script.Hold)
animate:Play()
end)
script.Parent.Unequipped:Connect(function()
equipped = false
if script.Parent:FindFirstChild("Handle") then
script.Parent.Handle.PointLight.Enabled = false
script.Parent.Handle.BillboardGui.Enabled = false
end
for _, ins in pairs(script.Parent.Handle:GetChildren()) do
if ins:IsA("Sound") then
ins:Stop()
elseif ins:IsA("PointLight") then
ins.Enabled = false
end
end
if animate then
animate:Stop()
end
if animate2 then
animate2:Stop()
end
end)
LocalHandler
local mouse = game.Players.LocalPlayer:GetMouse()
local equipped = false
local connection
local connection2
local active = false
local debounce = false
local isSemi = true
script.Parent.Equipped:Connect(function()
equipped = true
connection = mouse.Button1Down:Connect(function()
if equipped == true and debounce == false then
if isSemi == false then
active = true
repeat
if debounce == false then
debounce = true
local mousePos = mouse.Hit.Position
script.Parent.RequestFire:FireServer(mousePos)
end
wait(0.08)
debounce = false
until active == false
elseif isSemi == true then
if debounce == false then
debounce = true
local mousePos = mouse.Hit.Position
script.Parent.RequestFire:FireServer(mousePos)
wait(0.3) ----------- Change The CoolDown Each Shot
debounce = false
end
end
end
end)
connection2 = mouse.Button1Up:Connect(function()
if equipped == true then
active = false
end
end)
end)
script.Parent.Unequipped:Connect(function()
equipped = false
active = false
connection:Disconnect()
connection2:Disconnect()
end)
If You Can Help Please Reply, I Need This For My Game