You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
A gun that works -
What is the issue? Include screenshots / videos if possible!
Errors -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
i tried to remove some function from the server scripts
Server Code:
local Modules = ReplicatedStorage.Modules
local Events = ReplicatedStorage.Events
local FastCastRedux = require(Modules.FastCastRedux)
local BulletTemplate = script.Bullet
local function FastCastOnLengthChange(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.LookAt(lastPoint, lastPoint + direction):ToWorldSpace(offset)
end
end
local function FastCastOnHit(Caster, result, velocity, bullet, Damage)
local Hit = result.Instance
local Player = Players:GetPlayerFromCharacter(Hit:FindFirstAncestorWhichIsA("Model"))
local Character = Player.Character
Character:FindFirstChild("Humanoid"):TakeDamage(Damage)
Debris:AddItem(bullet)
end
local function GunCast(Player, Origin, Direction, Velocity, Range, Damage)
local FastCastRay = FastCastRedux.new()
local FastCastParams = RaycastParams.new()
local FastCastBehavior = FastCastRedux.newBehavior()
FastCastBehavior.MaxDistance = Range
FastCastBehavior.RaycastParams = FastCastParams
FastCastBehavior.AutoIgnoreContainer = false
FastCastBehavior.CosmeticBulletContainer = workspace.BulletFolder
FastCastBehavior.CosmeticBulletTemplate = BulletTemplate
FastCastParams.FilterType = Enum.RaycastFilterType.Blacklist
FastCastParams.FilterDescendantsInstances = {Player.Character, workspace.BulletFolder}
FastCastRay:Fire(Origin, Direction, Velocity, FastCastBehavior)
FastCastRay.LengthChanged:Connect(FastCastOnLengthChange)
FastCastRay.RayHit:Connect(FastCastOnHit)
end
Events.GunCast.OnServerEvent:Connect(GunCast)
Client Script:
local Tool = script.Parent
local Handle = Tool.Handle
local FirePoint = Handle.FirePoint
local Players = game.Players
local Player = Players.LocalPlayer
local ReplicatedStorage = game.ReplicatedStorage
local Mouse = Player:GetMouse()
local GunSettings = {
Range = 1000,
Velocity = 900,
Damage = 20,
}
Tool.Activated:Connect(function()
local Origin = FirePoint.WorldPosition
local Direction = (Mouse.Hit.Position - Origin).Unit
print(Direction, Origin)
ReplicatedStorage.Events.GunCast:FireServer(Player, Origin, Direction, GunSettings.Range, GunSettings.Damage)
end)
I never used fastcast before
would be nice if you help!
thanks!