Okay, So I got a artillery system and I made the shell (round, bullet whatever you call it) explode on .Touched event. However, im noticing that the .Touched event fires like after 0.5 seconds or something. Basically it fires late. I need alternative’s to .Touched event.
Here’s my code :
—ClonedShell.Touched:Connect(function(hit)
print(hit.Name…" ; exploded")
local Explosion = Instance.new(“Explosion”, workspace)
Explosion.Position = ClonedShell.Position
Explosion.Hit:Connect(function(otherPart)
if otherPart.Parent:FindFirstChild(“Humanoid”) then
otherPart.Parent.Humanoid.Health = 0
print(“killed”)
ClonedShell.Explosion:Play()
ClonedShell:Destroy()
print("done")
end
end)
end)
so when the shell hits something, it bounces off for once and THEN triggers the .Touched event
First devforum post btw so sorry for any mistakes in the topic.
This is perhaps because you’re running the Event on the Server, and so the latency of a moving projectile and the Touched event is causing it to seem like it’s late.
If you are doing this Server side, I suggest that you move over to having the Server tell the Clients to replicate the effect on the Client side and handle the Touched there.
Here’s the link to everything you’d need to learn about RemoteEvents to achieve this.
hm okay, but let me tell u the whole concept how this thing works. first there’s a text button which triggers a remote event which a script in serverscriptservice picks up and makes the artillery shoot. so you’re telling me to first fire the remote event which the artillery fires and then again fire a remote event to display the .touched event on all clients?
So what I would do if I was you in this case is the following:
You already fire a RemoteEvent to alert the Server that you’ve clicked the “Trigger” button.
The only thing that the Server should do with that Remote is
FireACannon:FireAllClients()
This Client event should replicate a Projectile and fire it on the Clients with a Touched event locally aswell. (Nothing should be moving on the Server)
If I read correctly. Then you shouldn’t trust the client for hit detection because it depends on the client. In addition, you shouldn’t use .Touched. It’s okay, but there are better ways.
Replicating Projectiles on the Client is absolutely fine and it’s how effects run at a good framerate and react well without having significantly delays.
As he’s using a Projectile, Touched is absolutely fine as well.
You could however take this a step further security wise by implementing Sanity checking on the Server if you want - although I’d argue it’s maybe not required until you see issues pop up as he’s using the Explosion Object rather than Rays.
In that case, you could use Ray casting to fire a ray in front of the falling part to detect a part in the path of it and follow out the explosion that way.
I’m currently on phone so I can’t provide the code well for that right now ! But you can definitely find it on the Forums.
Of course .Touched is fine just not the best there will always be a slight delay. Therefore, there are other methods like https://developer.roblox.com/en-us/api-reference/function/BasePart/GetTouchingParts
Also as I said client hit detection is not that good because laggy devices will not register as touched because the projectile could be somewhere else. Even though on your screen it could seem they got hit.
Why would calling the `:GetTouchingParts’ method and waiting for it to return a table be quicker than listening for an event which fires immediately on Touched ?
No argument of course- I’m just curious I usually use Raycasting.
Okay a update, i notice that the shell explode very correctly on things that are solid, like parts! however when i place a blank R6 rig and shoot on it, there’s a slight delay
btw can i use this same method to make shots (bullets) from a actual gun go smoother since when the bullet is released from server, it also has a slight delay before actually starting to move on clients