So when the client tries to fire a Projectile it sends a signal to the server, the server processes it and fires a remote to all clients, im Currently using SimpleCast, it does replicate the projectile aross all clients, but from other clients perspective they see the projectile stuck at it’s origin: Image (1 is the client who threw the projectile, it looks correct, but for other clients (2) it doesn’t look right, it’s stuck at the origin.)
Replicating:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Events = ReplicatedStorage.Events
local Replication = {}
function Replication.ValidateProjectile(Player, MousePosition: number, MaxDistance: number)
local Root = Player.Character.PrimaryPart
local CastParams = RaycastParams.new()
CastParams.FilterType = Enum.RaycastFilterType.Exclude
CastParams.FilterDescendantsInstances = { Player.Character }
local Origin = Root.Position
local Direction = (MousePosition - Origin).Unit * MaxDistance
Events.ReplicateProjectile:FireAllClients(Origin, Direction)
local RaycastResult = workspace:Raycast(Origin, Direction, CastParams)
if RaycastResult then
print(RaycastResult.Instance.Name)
end
end
function Replication.Start()
Events.ReplicateProjectile.OnServerEvent:Connect(Replication.ValidateProjectile)
end
return Replication
Visualizing projectile across all clients
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Events = ReplicatedStorage.Events
local SimpleCast = require(ReplicatedStorage.Modules.Packages.SimpleCast)
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local CastParams = RaycastParams.new()
CastParams.FilterType = Enum.RaycastFilterType.Exclude
CastParams.FilterDescendantsInstances = { Character }
local Projectile = ReplicatedStorage.Assets.Projectile:Clone()
local Caster = SimpleCast.new(Projectile, {
MaxLifeTime = 5,
CacheSize = 25,
CacheGrowthSize = 10,
Gravity = Vector3.new(0, -50, 0),
RaycastParam = CastParams,
OnCastHit = function()
end,
OnCastMove = nil,
OnCastTerminate = nil
})
local HandleProjectile = {}
function HandleProjectile.Start()
Events.ReplicateProjectile.OnClientEvent:Connect(function(Origin: Vector3, Direction: Vector3)
Caster:FireCast(Direction, Origin)
end)
end
return HandleProjectile
NOTE: I’ve aleardy tried to debug it, it sends the correct data and it receives the correct data, issue might lie in Caster:FireCast(Direction, Origin)
, this is how SimpleCast fires their projectiles:
function SimpleCast:FireCast(initVelocity: Vector3, initPosition: Vector3): CastData
debug.profilebegin("SimpleCastFire")
local newCast: CastData = self._casts:GetFromCache()
newCast.Object.Position = initPosition
newCast.InitVelocity = initVelocity
newCast.InitPosition = initPosition
newCast.LifeTime = 0
newCast.StartTime = os.clock()
debug.profileend()
return newCast
end
NOTE 2: This issue usually happens when i tried to throw something at the wall, on the baseplate it seems fine, sometimes it gets stuck sometimes it doesnt ¯_(ツ)_/¯
Any help is appreciated, I’ve been stuck on this for 2 days.