- What do you want to achieve? Keep it simple and clear!
i want to make a gun using fastcast(FastCastRedux)
- What is the issue? Include screenshots / videos if possible!
when i try the gun it generates the bullet twice, on right side of the wall and on left side of the wall, heres the video explaining it:
Server Code:
local Debris = game:GetService("Debris")
local players = game:GetService("Players")
local player = players:GetPlayers()
local tool = script.Parent
local event = game.ReplicatedStorage.Events.FireEvent
local FastCast = require(game.ReplicatedStorage.Modules.FastCastRedux)
local attachment = tool:WaitForChild(“Handle”).attachment
local bulletsFolder = workspace:FindFirstChild("BulletFolder") or Instance.new("Folder", workspace)
bulletsFolder.Name = "BulletFolder"
local bulletTemplate = Instance.new("Part")
bulletTemplate.Anchored = true
bulletTemplate.CanCollide = false
bulletTemplate.Shape = "Ball"
bulletTemplate.Size = Vector3.new(0.5, 0.5, 0.5)
bulletTemplate.Material = Enum.Material.Metal
--FastCast.VisualizeCasts = true
local castParams = RaycastParams.new()
castParams.FilterType = Enum.RaycastFilterType.Exclude
castParams.IgnoreWater = true
local caster = FastCast.new()
local castBehavior = FastCast.newBehavior()
castBehavior.RaycastParams = castParams
castBehavior.Acceleration = Vector3.new(0, -workspace.Gravity, 0)
castBehavior.AutoIgnoreContainer = false
castBehavior.CosmeticBulletContainer = bulletsFolder
castBehavior.CosmeticBulletTemplate = bulletTemplate
local function OnEquipped()
castParams.FilterDescendantsInstances = {tool.Parent, bulletsFolder, player}
end
local function OnLengthChange(cast, lastpoint, direction, length, velocity, bullet)
if bullet then
local bulletLength = bullet.Size.Z/2
local offset = CFrame.new(0, 0, -(length - bulletLength))
bullet.CFrame = CFrame.lookAt(lastpoint, lastpoint + direction):ToWorldSpace(offset)
end
end
local function OnRayHit(cast, result, velocity, bullet)
local hit = result.Instance
local character = hit:FindFirstAncestorWhichIsA("Model")
if character and character:FindFirstChild("Humanoid") then
character.Humanoid:TakeDamage(50)
end
Debris:AddItem(bullet, 2)
end
local function fire(Player, MousePos)
local origin = attachment.WorldPosition
local direction = (MousePos - origin).Unit
caster:Fire(origin, direction, 1000, castBehavior)
end
tool.Equipped:Connect(OnEquipped)
event.OnServerEvent:Connect(fire)
caster.LengthChanged:Connect(OnLengthChange)
caster.RayHit:Connect(OnRayHit)
thanks. -How4rdy.