.Touched is too fast

So recently i had a setup to see if a target was hit and where it was hit at specifically. my method to do this was name the different sections of targets with numbers 10, 20 , 30 , 50 , 100 and if tonumber(part.Name) then anchor it. to have it stick to the target. sadly what ends up happening is the game calculates where it would hit and just kinda leaves it floating mid flight.

any ideas?

script.Parent.Touched:Connect(function(target)
	print(target)
	if tonumber(target.Name) then
		game.ServerScriptService.ModificationsStats.Points.Value = tonumber(target.Name)
		script.Parent.Material = Enum.Material.Neon
		script.Parent.BrickColor = BrickColor.new("Institutional white")		
		wait()
		script.Parent.Anchored = true
	end
end)

wait()
script.Parent.BodyVelocity:Destroy()
wait(5)
script.Parent:Destroy()
1 Like

you could wait until the parts anchored (if it qualifies) before continuing the rest of the code.

1 Like

how would that help? it would just anchor way to soon


it literally calculates as a touch only a few studs after it leaves the barrel. and i know it is because its printing the name of the target part it touches

1 Like

your somehow checking the name of the target when it touches something without even comparing it to the part you wanted to touch:

correct me if Im wrong with this, Im not sure with this answer because I haven’t seen a thing of what’s happening.

1 Like

You could try checking the magnitude of the bullet to see if it’s close enough to be anchored.

if (target.Position - script.Parent.Position).magnitude <= range then
 -- anchor
end
1 Like

no part in the game’s name is a number automatically a name is a string if i am able to covert that string to a number then tonumber() is = to true and not nil.

1 Like

that’s way to complicated for the current setup. because the target board can be set further by the player to get more points. and still kinda unreliable since of delay, ive been looking into this network ownership thing.

1 Like

have you tried setting the networkowner of the part with the touched function connected to it to nil? I heard that may work.

1 Like

i kinda grasp the concept of it, and ive tried locking ownership to server and to each player, but doesnt seem to do much and im not getting an error.

1 Like

With most guns I’ve heard it’s best to use Raycasting to get the target. Touched is a bit finicky.

RaycastResult | Roblox Creator Documentation
Raycasting | Roblox Creator Documentation

2 Likes