.-.
local Player = game.Players.LocalPlayer
local Char = ((Player.Character and Player.Character.Parent) and Player.Character) or Player.CharacterAdded:Wait()
local Humanoid = Char:WaitForChild("Humanoid")
local HumanoidRoot = Char:WaitForChild("HumanoidRootPart")
---Services
local Rep = game:GetService("ReplicatedStorage")
local RepModels = Rep:WaitForChild("Models")
local RepEvents = Rep:WaitForChild("RemoteEvents")
local TweenService = game:GetService("TweenService")
local CAS = game:GetService("ContextActionService")
local CollectionService = game:GetService("CollectionService")
local Debris = game:GetService("Debris")
local Mouse = Player:GetMouse()
---Module
local ToolModule = require(game.ReplicatedStorage.ModuleScript)
----
local PlayerConfig = Char:WaitForChild("Player_Configuration")
local Weapon_Config = script:WaitForChild("Configuration")
local UniConFig = script.Parent.UniversualTool_Configuration
local StateAnims = UniConFig:WaitForChild("StateAnimations")
local CombatAnims = UniConFig:WaitForChild("CombatRanged_Animations")
local Muzzle = script.Parent:WaitForChild("Muzzle")
local Accuracy = Weapon_Config.Accuracy
local Damage = Weapon_Config.Damage
local MagSize = Weapon_Config.MagSize
local BulletSpeed = Weapon_Config.Bullet.BulletSpeed
local BulletTime = Weapon_Config.Bullet.BulletTime
local BulCount = 1
--
local LoadingAction = PlayerConfig:WaitForChild("DoingAction")
---Bullet
local DefultBullet = RepModels:WaitForChild("Bullet")
local BulletList = {
}
local BlackListTouch = {
Char,
script.Parent,
BulletList
}
----Functions
function DebrisV2(Instance_Tag, DelayTime, CommandType, Table_Tag)
delay(DelayTime, function()
if CommandType == "Destroy" then
Instance_Tag:Destroy()
elseif CommandType == "Table Destroy" then
table.remove(Table_Tag, Instance_Tag)
end
end)
end
function doActionStun(ActionTime)
LoadingAction.Value = true
delay(ActionTime,function()
LoadingAction.Value = false
end)
end
function LocalBulletCreate(BulletModel, parent, Pos, Dist, Speed, Accuracy, dmg)
if BulletModel ~= nil then
local CanHit = true
local Instance_Create = BulletModel:Clone()
CollectionService:AddTag(Instance_Create,"Bullet")
table.insert(BulletList,Instance_Create)
local TableNum = table.find(BulletList,Instance_Create)
Instance_Create.Parent = parent
Instance_Create.Position = Pos
Instance_Create.CFrame = CFrame.lookAt(Pos,Dist) * Accuracy
Instance_Create.Anchored = false
TweenService:Create(Instance_Create, TweenInfo.new(0.25,Enum.EasingStyle.Linear,Enum.EasingDirection.In), {Velocity = Instance_Create.CFrame.lookVector * Speed}):Play()
Debris:AddItem(Instance_Create,6)
delay(6,function()
table.remove(BulletList,TableNum)
end)
Instance_Create.Touched:Connect(function(hit)
if CanHit == true then
if hit and not table.find(BlackListTouch,hit.Parent) and not table.find(BulletList, hit) then
if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
local humanoidH12 = hit.Parent:FindFirstChild("Humanoid")
RepEvents:FindFirstChild("DamageAdd"):FireServer(humanoidH12, dmg)
Instance_Create:Destroy()
table.remove(BulletList,TableNum)
else
Instance_Create:Destroy()
table.remove(BulletList,TableNum)
end
end
end
end)
return Instance_Create
end
end
--Combat
function Fire(actionName, inputState, inputObject)
if LoadingAction.Value == false and LoadingAction.HardLock.Value == false then
if inputState == Enum.UserInputState.Begin then
doActionStun(0.5)
local Orientation = CFrame.new(HumanoidRoot.Position, Mouse.Hit.Position)
local x, y, z = Orientation:ToEulerAnglesYXZ()
local BulletToRootRot = CFrame.Angles(x, y, z)
Humanoid:LoadAnimation(CombatAnims:WaitForChild("Fire_Weapon")):Play()
HumanoidRoot.Orientation = Vector3.new(HumanoidRoot.Orientation.X, y, HumanoidRoot.Orientation.Z)
task.wait(0.05)
for count = 1, BulCount do
local Ran1 = math.random(-Accuracy.Value,Accuracy.Value)/100
local Ran2 = math.random(-Accuracy.Value,Accuracy.Value)/100
local Ran3 = math.random(-Accuracy.Value,Accuracy.Value)/100
LocalBulletCreate(DefultBullet, workspace, Muzzle.Position, Mouse.Hit.Position, BulletSpeed.Value, CFrame.Angles(math.rad(Ran1),math.rad(Ran2),math.rad(Ran3)), Damage.Value)
-- RepEvents:FindFirstChild("Bullet"):FireServer(DefultBullet, workspace, Muzzle.Position, Mouse.Hit.Position, BulletSpeed.Value, CFrame.Angles(math.rad(Ran1),math.rad(Ran2),math.rad(Ran3)), Damage.Value)
end
end
end
end
---Connections
CAS:BindAction("FireWeapon", Fire, true, Enum.UserInputType.MouseButton1)