ignore anything commented out most of it is by my friend who made the script
modular script that handles anything gun related
function Shoot(Player, target, otherChar)
warn("Shoot Request[RECIEVED]: " .. Player.Name.. " --> " .. otherChar.Name)
if Player.Character == nil then
return
end
local character = Player.Character
if character:FindFirstChild("Humanoid") == nil then
return
end
if character.Humanoid.Health == 0 then
return
end
if GunFunctions.TryGetCharacterGun(character) == nil then
return
end
--TEST IG COULD WORK BUT IDK
if character:GetAttribute("GunTimer") <= 0 then
return
end
local player = Players:GetPlayerFromCharacter(character)
local Gun = GunFunctions.TryGetCharacterGun(character)
if character:GetAttribute("GunEquipped") == true and character:GetAttribute("CanShoot") == true then
if character:GetAttribute("Reloading") == false then
--TRACER (this will be long)
local ShowTracer = false
local Muzzle = Gun:FindFirstChild("Muzzle")
local TracerBeam = Muzzle:FindFirstChild("Beam")
local TracerAtt0 = Muzzle:FindFirstChild("Att0")
local TracerAtt1 = Muzzle:FindFirstChild("Att1")
local MuzzleFlashP = Muzzle:FindFirstChild("MuzzleFlashParticle")
local MuzzleFlashL = Muzzle:FindFirstChild("MuzzleFlashLight")
if TracerAtt0 == nil or TracerAtt1 == nil or TracerBeam == nil --[[or target == nil]] then
return
end
if TracerAtt0:IsA("Attachment") and TracerAtt1:IsA("Attachment") and TracerBeam:IsA("Beam") --[[ and typeof(target) == "Vector3"]] then
local GunShotSound = Gun.GunSounds.GunShotSound
AnimTracks.PlayPlayerAnim(player.Name, "ShootAnim")
GunShotSound:Play()
--[[
local clonedAtt0 = TracerAtt0:Clone()
clonedAtt0.Parent = TracerAtt0.Parent
local clonedAtt1 = TracerAtt1:Clone()
clonedAtt1.Parent = TracerAtt1.Parent
local clonedBeam = TracerBeam:Clone()
clonedBeam.Parent = TracerBeam.Parent
]]
local clonedMFP = MuzzleFlashP:Clone()
clonedMFP.Parent = MuzzleFlashP.Parent
local clonedMFL = MuzzleFlashL:Clone()
clonedMFL.Parent = MuzzleFlashL.Parent
--[[
clonedAtt1.WorldPosition = target
clonedBeam.Attachment1 = clonedAtt1
clonedBeam.Attachment0 = clonedAtt0
]]
--hacky fix but does for now
local BeamPart = Instance.new("Part", workspace)
BeamPart.Anchored = true
BeamPart.Transparency = 1
BeamPart.CanCollide = false
BeamPart.CanQuery = false
BeamPart.CanTouch = false
BeamPart.CFrame = TracerAtt0.WorldCFrame
--[[
clonedAtt0.Parent = BeamPart
clonedAtt1.Parent = BeamPart
clonedBeam.Parent = BeamPart
]]
clonedMFP.Enabled = true
clonedMFL.Enabled = true
--[[
Debris:AddItem(clonedBeam, 0.2)
Debris:AddItem(clonedAtt0, 0.2)
Debris:AddItem(clonedAtt1, 0.2)
Debris:AddItem(BeamPart, 0.2)
]]
Debris:AddItem(clonedMFP, 0.15)
Debris:AddItem(clonedMFL, 0.15)
end
if otherChar == nil then
return
end
local returnResult = false
--local otherChar = rayresult.Instance:FindFirstAncestorOfClass("Model")
local otherPlayer = Players:GetPlayerFromCharacter(otherChar)
local Hum = otherChar:FindFirstChild("Humanoid")
if Hum and Hum.Health ~= 0 and otherChar:GetAttribute("GunName") ~= nil--[[ and otherChar:GetAttribute("Ragdolled") ~= true]] then
AnimTracks.StopPlayerAnim(player.Name, "ShootAnim")
GunFunctions.UnequipGun(Player.Character)
local GunTimer = character:GetAttribute("GunTimer")
if GunTimer <= 0 then
character.Humanoid.Health = 0
return
end
--[[
GunFunctions.EquipGun(otherChar)
BE_SetRoundStatus:Fire(otherPlayer.Name .. " has the Gun!")
]]
task.spawn(function()
warn("Shoot Request[CONFIRMED]: " .. Player.Name.. " --> " .. otherChar.Name)
--tako insert
if Player.Character:FindFirstChild("Humanoid") then
Player.Character.Humanoid.WalkSpeed = 28
end
otherPlayer:SetAttribute("LastShotBy", Player.Name)
BE_Ragdoll:Fire(otherChar)
local humanoidRootPart = otherChar:FindFirstChild("HumanoidRootPart")
local ForceAtt0 = Instance.new("Attachment", humanoidRootPart)
local VectorForce = Instance.new("VectorForce", humanoidRootPart)
local hitDirection = (humanoidRootPart.Position - Player.Character.HumanoidRootPart.Position).unit
hitDirection *= Vector3.new(2900, 100, 2900)
--warn(hitDirection)
--[[
-- Calculate the direction vector from the attachment to the target part
local direction = (Player.Character.Torso.Position - ForceAtt0.WorldPosition).Unit
-- Calculate the CFrame that points the attachment towards the target
local lookAtCFrame = CFrame.lookAt(ForceAtt0.WorldPosition, Player.Character.Torso.Position)
-- Apply the 180-degree rotation to the lookAtCFrame
local rotatedCFrame = lookAtCFrame * CFrame.Angles(0, math.rad(180), 0)
-- Apply the rotated CFrame to the attachment
ForceAtt0.CFrame = rotatedCFrame
]]
--ForceAtt0.CFrame = ForceAtt0.CFrame * CFrame.Angles(0, math.rad(180), 0)
--[[
if Hum.FloorMaterial == Enum.Material.Air then
VectorForce.Force = Vector3.new(0, 0, 2000)
else
VectorForce.Force = Vector3.new(0, 0, 5000)
end
]]
VectorForce.Force = hitDirection
VectorForce.Attachment0 = ForceAtt0
VectorForce.ApplyAtCenterOfMass = true
task.wait(0.1)
VectorForce:Destroy()
ForceAtt0:Destroy()
task.wait(1.6)
if Player.Character:FindFirstChild("Humanoid") then
Player.Character.Humanoid.WalkSpeed = 20
end
BE_UnRagdoll:Fire(otherChar)
task.wait(0.2)
GunFunctions.SetPlayerWithGun(otherPlayer)
end)
--Has to be spawned cuz it delays by 1 second idk WHYYYY (FIGURE OUT LATER IF IT HAS A PREF HIT)
local GunHitSound = Gun.GunSounds.GunHitSound
GunHitSound:Play()
returnResult = true
end
Gun:SetAttribute("Magazine", Gun:GetAttribute("Magazine") - 1)
GunFunctions.StartReloadTimer(character)
return returnResult
else
end
else
end
end
RF_ShootRequest.OnServerInvoke = Shoot
local side
function Input(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 and Player:GetAttribute("AssetsLoaded") then
--centerTestPart.CFrame = CFrame.new(ViewportPointToWorldCoordinates())
local Humanoid = Character:FindFirstChild("Humanoid")
if Humanoid == nil then
return
end
if Character:GetAttribute("CanShoot") == true and Character:GetAttribute("Reloading") == false and Character:GetAttribute("GunTimer") > 0 and Humanoid.Health > 0 then
local target = ViewportPointToWorldCoordinates()
if DebugSwitch then
local debugPart = Instance.new("Part", game.Workspace)
debugPart.Name = "DebugShootPart"
debugPart.Anchored = true
debugPart.CanCollide = false
debugPart.CanTouch = false
debugPart.CanQuery = false
debugPart.Transparency = 0.5
debugPart.Shape = Enum.PartType.Ball
debugPart.BrickColor = BrickColor.new(Color3.fromRGB(255, 176, 0))
debugPart.Position = target
Debris:AddItem(debugPart, 10)
end
local rayParams = RaycastParams.new()
rayParams.FilterType = Enum.RaycastFilterType.Exclude
rayParams.FilterDescendantsInstances = {Player:GetDescendants(), Character:GetDescendants()}
local rayCast = Ray.new()
local originPoint = Character:FindFirstChild("Head").Position
local rayDestinationPoint = target
local rayDirectionWay = (rayDestinationPoint - originPoint).Unit
local rayresult = workspace:Raycast(originPoint, rayDirectionWay * 300, rayParams)
local intersection = rayresult and rayresult.Position or originPoint + rayDirectionWay * 300
local distance = (originPoint - intersection).Magnitude
if rayresult.Instance:FindFirstAncestorOfClass("Model") ~= nil then
local otherChar = rayresult.Instance:FindFirstAncestorOfClass("Model")
--warn(otherChar.Name)
task.spawn(Recoil)
local Hum = otherChar:FindFirstChild("Humanoid")
if Hum and Hum.Health ~= 0 and otherChar:GetAttribute("GunName") ~= nil then
task.spawn(function()
if HitLabel.Visible == false then
HitLabel.Visible = true
HitPlayerLabel.Visible = true
end
Hitmarker.Visible = true
HitPlayerLabel.Text = otherChar.Name
task.wait(0.3)
Hitmarker.Visible = false
task.wait(0.2)
if HitLabel.Visible == true then
HitLabel.Visible = false
HitPlayerLabel.Visible = false
end
end)
end
RF_ShootRequest:InvokeServer(target, otherChar)
end
--[[
task.spawn(Recoil)
if target then
local result = RF_ShootRequest:InvokeServer(target)
if result == true then
--DO STUFF HERE ON CLIENT IF HIT
end
end
]]
else
end
end
if input.KeyCode == Enum.KeyCode.F3 then
if DebugSwitch == true then
DebugSwitch = false
NotifModule.UINotify("disabled hit visualisation", 24)
else
DebugSwitch = true
NotifModule.UINotify("enabled hit visualisation", 24)
end
end
end
UIS.InputBegan:Connect(Input)