I was using the FastCastRedux module on my game and it was working fine then it stopped working after I changed something(I cant figure out what) and I cant get it to work again. I have 2 other guns that work fine with the module and the only difference is that this one is a shotgun and the other ones aren’t. I hadnt messed with the server script or the module at all only client script.
Client:
wait()
local tool = script.Parent
local plr = game:GetService('Players').LocalPlayer
local userInput = game:GetService('UserInputService')
local event = tool:WaitForChild('GunEvent')
local char = workspace:WaitForChild(plr.Name)
local hum = char:WaitForChild('Humanoid')
local mouse = plr:GetMouse()
local camera = workspace.CurrentCamera
local ammoGui = plr.PlayerGui:WaitForChild('AmmoGui')
local ammoText = ammoGui:WaitForChild('Frame'):WaitForChild('Ammo')
local clip = tool.Clip
local maxAmmo = tool.MaxAmmo.Value
local cooldown = 1.2
local AMMO = 4
local reloading = false
local onCooldown = false
local reloadsfx = tool.reloadsfx
local idleanim = hum.Animator:LoadAnimation(tool:WaitForChild('holding'))
local shootanim = hum.Animator:LoadAnimation(tool:WaitForChild('shoot'))
local function stopAnims()
idleanim:Stop()
shootanim:Stop()
end
tool.Equipped:Connect(function()
ammoGui.Enabled = true
ammoGui.Frame.FireMode.Text = tool:GetAttribute('FireMode')
ammoGui.Frame.Gun.Text = tool.Name
ammoText.Text = (clip.Value.. '/' .. maxAmmo)
idleanim:Play()
end)
tool.Unequipped:Connect(function()
ammoGui.Enabled = false
stopAnims()
end)
tool.Activated:Connect(function()
if clip.Value > 0 then
if reloading == false then
if onCooldown == false then
local position = userInput:GetMouseLocation()
local ray = camera:ViewportPointToRay(position.X,position.Y)
onCooldown = true
clip.Value -= 1
shootanim:Play()
event:FireServer(ray)
wait(cooldown)
onCooldown = false
end
end
end
end)
local function reload()
local backpack = script.Parent.Parent:IsA('Backpack')
if not backpack then
if reloading == false then
if maxAmmo ~= 0 then
if clip.Value < AMMO and maxAmmo > 0 then
if maxAmmo - (AMMO - clip.Value) >= 0 then
reloading = true
local sum = (AMMO - clip.Value)
for i = 1, sum do
reloadsfx:Play()
reloadsfx.Ended:Wait()
end
maxAmmo = maxAmmo - (AMMO - clip.Value)
clip.Value = AMMO
reloading = false
else
reloading = true
local sum = (AMMO - clip.Value)
for i = 0, sum do
reloadsfx:Play()
reloadsfx.Ended:Wait()
end
clip.Value = clip.Value + maxAmmo
maxAmmo = 0
ammoText.Text = (clip.Value.. '/' .. maxAmmo)
reloading = false
end
end
end
end
end
end
clip:GetPropertyChangedSignal('Value'):Connect(function()
ammoText.Text = (clip.Value.. '/' .. maxAmmo)
end)
ammoGui.Reload.MouseButton1Click:Connect(reload)
userInput.InputBegan:Connect(function(object)
if (object.KeyCode == Enum.KeyCode.R) then
reload()
end
end)
Server:
local tool = script.Parent
local event = tool:WaitForChild('GunEvent')
local fastcast = require(tool.FastCastRedux)
local firepoint = tool.Handle.FirePoint
local bulletsFolder = game.Workspace:FindFirstChild('Bullets') or Instance.new('Folder', workspace)
bulletsFolder.Name = 'Bullets'
local MAX_DISTANCE = 100
local HOW_MANY_PELLETS = tool.Bullets.Value
local MIN_SPREAD = .1
local MAX_SPREAD = 4
local VELOCITY = 200
local DAMAGE = 14
local bulletTemp = tool.Handle:Clone()
bulletTemp.Name = 'Bullet'
bulletTemp.Anchored = false
bulletTemp.CanCollide = false
bulletTemp.Transparency = 0
local weld = bulletTemp:FindFirstChild('Weld')
weld:Destroy()
fastcast.VisualizeCasts = false
local caster = fastcast.new()
local castParameters = RaycastParams.new()
castParameters.FilterType = Enum.RaycastFilterType.Blacklist
castParameters.IgnoreWater = true
local castBehavior = fastcast
castBehavior.RaycastParams = castParameters
castBehavior.Acceleration = Vector3.new(0,-workspace.Gravity,0)
castBehavior.AutoIgnoreContainer = false
castBehavior.CosmeticBulletContainer = bulletsFolder
castBehavior.CosmeticBulletTemplate = bulletTemp
local function getMousePosition(unitRay)
local ori,dir = unitRay.Origin, unitRay.Direction * MAX_DISTANCE
local result = workspace:Raycast(ori,dir,castParameters)
return result and result.Position or ori + dir
end
caster.RayHit:Connect(function(cast, result, velocity, bullet)
local hit = result.Instance
local char = hit:FindFirstAncestorWhichIsA('Model')
if char and char:FindFirstChild('Humanoid') then
char.Humanoid:TakeDamage(DAMAGE)
end
game:GetService('Debris'):AddItem(bullet,.3)
end)
local function Shoot(direction)
local directionCFrame = CFrame.new(Vector3.new(), direction)
local spreadDirection = CFrame.fromOrientation(0,0,math.random(0,math.pi * 2))
local spreadAngle = CFrame.fromOrientation(math.rad(math.random(MIN_SPREAD,MAX_SPREAD)),0,0)
local direction = (directionCFrame * spreadDirection * spreadAngle).LookVector
caster:Fire(firepoint.WorldPosition, direction, VELOCITY, castBehavior)
end
tool.Equipped:Connect(function()
castParameters.FilterDescendantsInstances = {tool.Parent}
end)
event.OnServerEvent:Connect(function(player, ray)
if tool.Parent:IsA('Backpack') then return end
local mousePosition
local position = getMousePosition(ray)
local direction = (position - firepoint.WorldPosition).Unit
for i = 1,HOW_MANY_PELLETS do
Shoot(direction)
end
end)
caster.LengthChanged:Connect(function(cast, lastPoint, direction, displace, segmentVelocity, bullet)
bulletTemp.CFrame = CFrame.lookAt(lastPoint+(direction * displace), lastPoint)
end)
Error in module:
if (castDataPacket.HighFidelitySegmentSize <= 0) then
error("Cannot set FastCastBehavior.HighFidelitySegmentSize <= 0!", 0)
end