Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tool = script.Parent.Parent
- local player = game:GetService("Players").LocalPlayer
- local mouse = player:GetMouse()
- local hole = tool:WaitForChild("hole")
- local handle = tool:WaitForChild("handle")
- local actioService = game:GetService("ContextActionService")
- local mouseDown = false
- local equipped = false
- --Folder--
- local animations = tool:WaitForChild("Animations")
- local configs = tool:WaitForChild("Configs")
- local remotes = tool:WaitForChild("Remotes")
- --Animations--
- local recoilAnim = animations:WaitForChild("Recoil")
- local reloadAnim = animations:WaitForChild("Reload")
- local holdAnim = animations:WaitForChild("Hold")
- --Animations Tracks--
- local recoilTrack
- local ReloadTrack
- local holdTrack
- --configs--
- local allowTracing = configs:WaitForChild("AllowTracing")
- local range = configs:WaitForChild("Range")
- --remotes--
- local canShoot = remotes:WaitForChild("CanShoot")
- local canReload = remotes:WaitForChild("CanReload")
- local hitRemote = remotes:WaitForChild("Hit")
- local reloadRemote = remotes:WaitForChild("Reload")
- local shootRemote = remotes:WaitForChild("Shoot")
- --Assets--
- local flashGui = hole:WaitForChild("FlashGui")
- --functions--
- local function equip()
- equipped = true
- --Get Humanoid
- local character = player.Character or player.CharacterAdded:wait()
- local humanoid = character:WaitForChild("Humanoid")
- if humanoid then
- --load animation--
- pcall(function()
- --hold Animation--
- holdTrack = humanoid:LoadAnimation(holdAnim)
- holdTrack:Play()
- end)
- --reload animation--
- pcall(function()
- --hold Animation--
- reloadTrack = humanoid:LoadAnimation(reloadAnim)
- end)
- --Recoil animation--
- pcall(function()
- --hold Animation--
- recoilTrack = humanoid:LoadAnimation(recoilAnim)
- end)
- end
- end
- local function unequip()
- equipped = false
- --stop animation--
- if holdTrack then
- holdTrack:Stop()
- end
- if ReloadTrack then
- reloadTrack:stop()
- end
- if recoilTrack then
- recoilTrack:stop()
- end
- end
- local function reload()
- if canReload:InvokeServer() then
- --reload--
- reloadRemote:FireServer()
- if reloadTrack then
- reloadTrack:Play()
- end
- end
- local function fire()
- --checks--
- if canShoot:InvokeServer() then
- end
- --Initialize--
- if recoilTrack then
- recoilTrack:play()
- end
- flashGui.enebled = true
- --cast ray--
- local ray = Ray.new(hole.Cframe.p, (mouse.hit.p - hole.Cframe.p).unit * range.value)
- local touch, position = workspace:FindPartOnRay(ray, player.Character, false, true )
- --hit detection--
- if touch then
- hitRemote:FireServer(touch)
- end
- shootRemote:FireServer()
- --trace--
- if allowTracing.Value then
- --create--
- local trace = Instance.new("Part")
- trace.Anchored = trace
- trace.CanCollide = false
- trace.Transparency = 0.5
- trace.BrickColor = BrickColor.new("Black")
- trace.Material = Enum.Material.SmoothPlastic
- --calculate
- local distance = (hole.CFrame.p - position).magnitude
- trace.Size = Vector3.new(0, 0, distance)
- trace.CFrame = CFrame.new(hole.CFrame.p, position)* CFrame.new(0,0, -distance/2)
- trace.parent = workspace
- --clean-up--
- game:GetService("Debris"):AddItem(trace, 0,1)
- wait(0.1)
- flashGui.enebled = false
- end
- end
- end
- --Event listeners--
- tool.Equipped:Connect(function()
- equip()
- --Automatic Fire--
- mouse.Button1Up:Connect(function()
- mouseDown = false
- end)
- tool.Activated:Conntect (function()
- mouseDown = true
- repeat
- wait(0.01)
- fire()
- until not mouseDown
- end)
- end)
- tool.Unequipped:Connect(unequip)
- actioService:BindAction("Reload", reload, false, Enum.KeyCode,R)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement