You broke it studio now stops responding if I try to add the model in. Only crashes with fastcast, can insert any other model from the toolbox, but not fastcast
^^^
Same problem as above, inserting the model causes my studio to crash.
Only for the FastCast models
Interesting! This seems to be a side effect of the Lua script analysis beta @NinjoOnline @20amir02 – disable this beta feature and then insert the model. It works fine there.
I’ll get this information to the right people as soon as I can. For now, you’ll need to disable the feature, I’m afraid.
Thank you for the solution, now i can use this module.
One roadblock I ran into is that I’ve been getting errors when I try to terminate the ActiveCast in the Casters LengthChanged event.
I seemed to stop the errors by adding a check in between the lines in the module.
SendLengthChanged(cast, lastPoint, rayDir.Unit, rayDisplacement, segmentVelocity, cast.RayInfo.CosmeticBulletObject)
if not cast.StateInfo then return end
cast.StateInfo.DistanceCovered += rayDisplacement
Though I do feel like there could’ve been a better method. Just letting you know.
You aren’t supposed to be terminating casts in LengthChanged anyway, let alone any event handler. Termination is more for if an outside source needs to come in and stop a cast, such as a network replication script.
I am looking for advice on how to set this up, because in my use case, I am not using a tool like the example gun. I have a single module that will be accessed by any player in the game, and the documentation for this FastCast states we should never be creating a new Caster each time we want to fire a bullet (in my case they are knives).
I notice that there is no :Destroy method in the FastCast constructors? Why is this? Where are the casters stored and how are they garbage collected if at all?
In my case, given that I have a single module for all players in the game, where would I be storing these casters for use when a player returns to the module after the initial time there? Should I create a table and when I create the new caster, put it in the table with the players UserId or something like that? I fi do that, then I have to track PlayerRemoving and cleanup after the player, which feels a little overly complicated.
My knife throwing ability has a longish cooldown, something like 10 seconds between throws, would it be OK to just create a new caster each time?
Thanks!
They are stored in your script when you instantiate them, and they are GC’d through stock Lua GC – Drop all references to the caster and it will be disposed of.
local myCaster = FastCast.new()
-- some use code here ...
myCaster = nil
-- caster instance will now be GC'd because there's no more references to it
Modules cache when require()
'd. Alongside this, I recommend a LocalScript
in StarterPlayerScripts
that instantiates the caster - scripts in that location will run once and never reload until the player flat out leaves the game and rejoins. All other client scripts can reference it via events or whatever it may be. If the player leaves, the script is destroyed, and by extension, the caster managed by that script will be GC’d. No need to track players leaving and joining on the clientside.
For the server, you should have one caster for all players – Presumably, the players will all be using the same knife. Think of a caster like a “factory” for projectiles - you only need one thing making the projectiles if there’s only one type of projectile. Each individual person does not need their own factory to create something for them on the server. A client should simply go to the server and say “Hey, I’m throwing a knife, can you make one for me?” and the server will do just that.
The client differs because if you plan to do rendering on the client, then the client needs to be independent of the server. It should still be one module, just each client should call FastCast.new()
once.
No, time does not change anything. A single unified caster is the way to go.
this is helpful, thank you!
I was doing some setup and simply requiring the latest version of the module yields all code in my game, I looked and on line 127 of the main script, Roblox studio is giving an error.
FastCastRedux - Roblox Studio (gyazo.com)
so all I am doing is just requiring the FastCastRedux module in a script, if I do that, it yields completely and the game wont run past that point. If I simply comment out that require, everything works fine.
Ah it’s just a warning, if you go to TypeDefinitions
, you will see that FastCastBehavior
defines CanPierceFunction: PierceFunction
(or whatever I put it as). It should have a ?
after it making PierceFunction?
which means that it’s able to be nil. You can make this edit yourself for now
will this stop the module from yielding? as it is now, i cant use the module at all.
The yielding might be due to something with Luau. It used to completely crash studio if you inserted it, now it just locks it up for about a second or two. Is this what’s happening in your script too?
Just yields indefinitely, no errors and no crash
Is there an older version of this module available, something more stable?
I can’t get this issue to occur, it may likely be in your script. Please check everything and make sure you haven’t made any mistakes (Did you try modifying the module to tinker with it and forget you did it? Try inserting a fresh copy.)
I did not modify anything, just required it from my script.
I had to literally copy and paste the entire code though because I use Rojo. Is there any way to download a file system version of the project?
EDIT: I went ahead and re-copy/pasted all the code into my file system and this time, I am not getting any yields. I was fairly sure I did a clean job, but I guess it was my own error. I am grateful for all of your work here but I have one request! Could you please upload this to GitHub so we can have a file system version of this code? That would be so helpful I think
This is incredibly useful, thank you!
Now, I just gotta figure out how to make a ammunition system, and it will work perfectly for my game, the API guide is really useful too.
In light of the recent requests for projectiles being 3D, I will be investigating methods of achieving this effect without extreme performance impacts. I have a few ideas:
1: Rotated Region3, but casts will be throttled to 30 or 15 FPS rather than 60. Most reliable, but also most expensive.
2: Derive from hitbox module by running several rays in parallel.
3: Try some tricks with using the cosmetic bullet (or a different part) for hit detection.
good luck you got this! You never fail to come through XD
Is there any way to rotate the cosmetic bullet? I’ve got a knife part that I’m throwing but it comes out vertical, and I just want to make it look like it’s pointing forward. Thanks!
Just edit the CFrame in the LengthChanged event.