Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Debris = game:GetService("Debris")
- local TweenService = game:GetService("TweenService")
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local Module = require(script.FastCastRedux)
- local Tool = script.Parent
- local RemoteEvent = Tool:WaitForChild("RemoteEvent")
- local GunConfig = Tool:WaitForChild("Configuration")
- local Bullet = ReplicatedStorage:FindFirstChild("Bullet")
- local Audio = Tool.Handle:FindFirstChild("Shoot")
- local OnCooldown = false
- function FolderStorage()
- local Folder = workspace:FindFirstChild("BulletStorage")
- if not Folder then
- Folder = Instance.new("Folder",workspace)
- Folder.Name = "BulletStorage"
- end
- return Folder
- end
- function Hit(Cast,Result)
- local Hit = Result.Instance
- if Hit then
- local Humanoid = Hit.Parent:FindFirstChildOfClass("Humanoid") or Hit.Parent.Parent:FindFirstChildOfClass("Humanoid")
- if Humanoid then
- Humanoid:TakeDamage(GunConfig.Damage.Value)
- end
- end
- end
- function RayUpdate(Cast, Origin, Direction, Length, Velocity, PartObject)
- if PartObject then
- local PartLength = PartObject.Size.Z/2
- local BaseCF = CFrame.new(Origin,Origin+Direction)
- TweenService:Create(PartObject,TweenInfo.new(((Origin-Direction).Magnitude/Velocity.Magnitude)/1.2),{CFrame = BaseCF*CFrame.new(0,0,-(Length-PartLength))}):Play()
- end
- end
- function RayTerminating(Cast)
- local RayInfo = Cast.RayInfo
- if RayInfo then
- local PartObject = RayInfo.CosmeticBulletObject
- if PartObject then
- TweenService:Create(PartObject,TweenInfo.new(.5),{Transparency = 1}):Play()
- Debris:AddItem(PartObject,.55)
- end
- end
- end
- RemoteEvent.OnServerEvent:Connect(function(Player,Position)
- if Position ~= nil and Player.Character and not OnCooldown then
- OnCooldown = true
- task.delay(GunConfig.ShootSpeed.Value,function()
- OnCooldown = false
- end)
- local FastCastRedux = Module.new()
- FastCastRedux.VisualizeCasts = false
- local Params = RaycastParams.new()
- Params.FilterType = Enum.RaycastFilterType.Blacklist
- Params.FilterDescendantsInstances = {Player.Character}
- Params.IgnoreWater = true
- local Behavior = Module.newBehavior()
- Behavior.RaycastParams = Params
- Behavior.MaxDistance = 3000
- Behavior.AutoIgnoreContainer = false
- Behavior.CosmeticBulletTemplate = Bullet
- Behavior.CosmeticBulletContainer = FolderStorage()
- Behavior.Acceleration = Vector3.new(0,GunConfig.BulletDrop.Value,0)
- Behavior.HighFidelityBehavior = Module.HighFidelityBehavior.Default
- local Origin = Tool.Handle.ShootPart.WorldPosition
- local Direction = CFrame.new(Origin)*CFrame.new(0,0,-100)
- local OriginToDirection = CFrame.new(Origin,Position).LookVector
- FastCastRedux:Fire(Origin,Direction.Position,OriginToDirection*GunConfig.Velocity.Value,Behavior)
- if Audio then
- local SFX = Audio:Clone()
- SFX.PlayOnRemove = true
- SFX.Parent = Audio.Parent
- SFX:Destroy()
- end
- FastCastRedux.RayHit:Connect(Hit)
- FastCastRedux.LengthChanged:Connect(RayUpdate)
- FastCastRedux.CastTerminating:Connect(RayTerminating)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement