Making a combat game with ranged weapons? FastCast may be the module for you!

This doesn’t solve the problem though…

A module is still loaded separately between server and clients. A change made by the server won’t be seen by the client.

1 Like

One piece of code that propagates between the server and client automatically is simply not possible. You must use a remote if you want to accomplish this. I suggested a common module because generally speaking, behaviors should be constant and see no changes during runtime. Why would you need to transmit changes across the network? What are you modifying?

2 Likes

The RaycastParameters.

It has to exclude the LocalPlayer’s character and the gun. The character can respawn and the gun can be added or removed.

The RaycastParameters have to change with them.

1 Like

What you do is pull a local copy for each player (and for the server) and set the parameters in the copy. The module storing the behaviors should function as a provider. You tell it “I want a behavior for xyz gun”, it gives you a behavior for xyz gun. That’s how you make it so you only need to go to one place to get a behavior.

local Provider = {}
local FastCast = require(...)

function Provider.GetBehaviorForCoolGun()
    local behavior = FastCast.newBehavior()
    behavior.blahblahblah = asdfg -- Set all props here, except for RaycastParams
    return behavior -- Then set RaycastParams from wherever this function was called.
end

return Provider
1 Like

Did that whole idea get scrapped? If not it will be very helpful for me and many other people too.

I’ve tried many methods of hit registration, and none of them compare to FastCast. Combined with PartCache, you can have some absolutely insane hit registration without nearly as much headache as any other method. It’s fairly straight foward to setup and is almost perfect. I would highly recommend checking this out.

Also, a similar module works for melee, that i’d also check out (link here) he also has a similar module to PartCache, but PartCache is better faster

1 Like

Hey EtiTheSpirit, I see that this is outdated in the title. If you have time, is it possible for you to make another tutorial for client replication? Thanks. Oh, and creating a separate model for it would be a great help. Thanks again!

I’ve read a few replies discussing how to make the client visualize the bullet. I’d just like to say that the code in the example laser gun model doesn’t give you exactly how you should do it, it’s just a very well-built hands-on reference. Many developers implement their own solutions.

A possible solution

Many games, like Arsenal - Roblox, sacrifices security for performance and quality. The bullets are managed purely from the client shooting it. What happens is:

  1. The client visualizes the server on fire, instantly
  2. The client fires a remote to server, which replicates the bullet to every other client.
  3. When the client managed bullet hits it’s target, it will fire another remote event, which tells the server to damage the player

Pros:

  • Performance is top-notch, bullets appear instantly and no replication lag would show for the bullet.
  • Server spends minimal computing on the bullets, saving performance for heavier tasks.

Cons:

  • This leaves your game very vulnerable to exploiters until you start adding sanity checks and etc.

Note: This may not necessarily be the best solution for all uses of this module, it depends completely on what you are using FastCast for.

How can I get the direction the cast came from in the rayhit event?

When I jump or am in midair, my cast won’t fire. Is this intented behaviour?

Hi, I have an issue;

Whenever I try to connect up RayHit to a ray hit function, it simply doesn’t fire the event at all and it doesn’t work. Here’s my code:

caster.RayHit:Connect(function()
	print('pew')
end)

Yes, I am 200% sure I fired the caster.
Yes, I am 100% sure I fired only one cast.
Yes, I am 100% sure I wired up the LengthChanged event.

@EtiTheSpirit Excellent module!

I had one question on the FastCastBehaviour instance. Its not clear to me from reading the docs that the API allows me to manage the size of the projectile after its fired. If I wanted the bullet template to say grow larger as it travelled is that possible within the current API? And if not do you have any recommendations for the cleanest way to manage that?

Thanks for making this! I don’t think the game I’m working on would be possible without it, and it certainly wouldn’t be so far along in development without it.

I have two questions for anyone who can help:

  1. How can I make the ray cast through players such that projectiles go through them?
  2. If I want a secondary fire functionality - which would necessarily behave differently - is it still best to avoid using a second caster?

Small suggestion:
Add projectile path prediction to simplify creating beams that indicate where the projectile will go.

1 Like
  1. You can edit the raycast parameters for the cast.
  2. I’m pretty sure that one caster would be enough, given that the projectiles are the same.

Hi
I have a remote that the client fires to tell the server it wants to fire a bullet. The server then handles the damage to other players of multiple guns in a central script. I’m stuck however at how I can get the player that fired the bullet from the serverscript.

I’m not supposed to add the RayHit connection under the OnServerEvent connection, so is there a way to pass information to Caster:Fire() that can be retrieved by Caster.RayHit()?

When receiving a remote event from a client to server, the first parameter on server is the player that fired it, So for Example

in a local script

Local RemoteEvent = -- to the remote event

RemoteEvent:FireServer() -- add some parameters to your likings

in a server

Local RemoteEvent = -- to the remote event

RemoteEvent.OnServerEvent:Connect(function(Player)
--do the fast cast here
End)

I believe this is the solution you wanted?

Yes, I can call Caster:Fire() inside the OnServerEvent, but how can I pass the player through to the RayHit event?

Connecting the event under the RemoteEvent is not an option, since it should only be connected once.

Well couldn’t you just make a new remote event and use that remote event in the RayHit event?

No a connection should only be connected once, not everytime the gun fires.