.Touched() Firing Too Early / Too Late

Upon collision, a ball should spawn right in the projectiles position, however it seems to delay, or fire too early, spawning the ball away from the target.

(11.07.2024_19.08.26_REC)

I do not really know how to fix it, or lower the delaying time.

local SubspaceTripmineExplosion = game:GetService("ServerStorage"):WaitForChild("ProjectilesAbilityParts"):WaitForChild("SubspaceTripmineExplosion")

Connection = script.Parent.Touched:Connect(function(hit)
	local Explosion = SubspaceTripmineExplosion:Clone()
	Explosion.Parent = game.Workspace
	Explosion.Position = script.Parent.Position
end)

(there is another script inside the SubspaceTripmineExplosion which tweens it)

1 Like

Is it anchored? And are you sure that the connection is set on time?

what is script.Parent.Position?

Usually positions take a bit to update so based on what I could see on your video it seems like the script.Parent.Position isnā€™t updating fast enough.

You could try using raycast to detect where is the projectile going to collide.

Also, would you mind sending me a file with your place?
If I get to check it I probably could solve this issue

There is a delay between the client character position and the position of the character on the server. You should fire a remote event from the client and pass the position to the server or create the effect on the client.

Also, the touch event should be created on the client, and the server should only listen for when to create the effect. You should also add in checks such as debounces or if the projectile still exists on the server so players donā€™t exploit your system and create endless effects on the server.

the script.Parent is the projectile (ball). I tried anchoring it when it collides with an object but it did not work. I canā€™t send the place right now beacuse it has lots of different stuff inside.

I figured out that the projectile explodes right at the collision position when the game is not laggy (It gives a slight lag when part explode). It probably is the problem.

Hey, if youā€™re having trouble with a script that stops a projectile on impact but ends up detecting the collision too early, too late, or even clips through the obstacle, hereā€™s a simple fix in two steps:

  1. Avoid using touch events. Instead, detect parts during each physics step.

  2. Use raycasts to check if the projectile clipped through the obstacle between rendered frames. (This happens when the projectile moves so fast that its position in the next frame skips past the obstacle, causing it to miss the collision.)

Hereā€™s a quick showcase: https://www.youtube.com/watch?v=RqF-oE060S8

Let me re-make your script lol

Thereā€™s a fully detailed script:

local SubspaceTripmineExplosion = game:GetService("ServerStorage"):WaitForChild("ProjectilesAbilityParts"):WaitForChild("SubspaceTripmineExplosion")

script.Parent.Touched:Connect(function(Touched)
	script.Parent.CanTouch = false -- Making the part untouchable to prevent from multiple explosions spawn
	local Player = game:GetService("Players"):GetPlayerFromCharacter(Touched.Parent) -- Identifying a player from the touched part
	
	if Player then -- Do something if it's a player
		local Explosion = SubspaceTripmineExplosion:Clone() -- Cloning the explosion
		Explosion.Parent = workspace -- Setting the parent of it
		Explosion.Position = script.Parent.Position -- Changing the explosion position to the part's position
		wait(30) -- Making something after 30 seconds delay
		script.Parent.CanTouch = true -- Make the part touchable again after 30 seconds and also touchable for other players in the game
	else
		script.Parent.CanTouch = true -- Make the part touchable again if it's not been touched by a player
	end
end)

Enjoy! :wink: