Issue on velocity ruining events

What do I want to achieve?

I want to make a projectile(from a boss)that shoots a part, and whenever that part touches a base part, It will anchor and then size up(meaning it will stick in place like a normal part) and whenever a player touches it they lose health.

Issue?

The projectile is moving so fast that it can’t recognize any base part. I think it may be this but there may be more reasons to why the touched event isn’t working.

What have I tried?

I tried to look at RunService because the frame rate seemed like my only viable option as it was probably faster and in more control of the game and what happens to the part. I did this by watching this video.

Server script(part of a bigger script):

			runservice.Stepped:Connect(function()
				print("Success")
				cloned.Touched:Connect(function(hit)
					if hit:IsA("BasePart") and not workspace:WaitForChild("Egg") then
						print(hit)
						if not debounce then
							debounce = true
							cloned.Anchored = true
							for i = 1,10 do
								if cloned.Size == Vector3.new(10,10,10) then
									break
								end
								cloned.Size = cloned.Size + Vector3.new(1,1,1)
								task.wait()
							end
							task.wait(10)
							cloned:Destroy()
							debounce = false
						end
					elseif hit.Parent:FindFirstChild("Humanoid") then
						if not debounce then
							print(hit)
							debounce = true
							cloned.Anchored = true
							hit.Parent.Humanoid:TakeDamage(25)
							for i = 1,10 do
								if cloned.Size == Vector3.new(10,10,10) then
									break
								end
								cloned.Size = cloned.Size + Vector3.new(1,1,1)
								task.wait()
							end
							task.wait(10)
							cloned:Destroy()
							debounce = false
						end
					end
				end)
			end)

Im not sure how your code works but generally I wouldn’t rely on the .Touched event. I would shoot a ray and check when it interfers with a physical object. Let the part fly with the ray and destroy it as soon as the distance between rayOrigin and object interfered is reached. Then just spawn the part again at the position the ray hit.

1 Like

I don’t know anything about ray casting, I’ll go check some videos.

  • You could use a local script and not a server script as .touched updates on client faster.
1 Like

^ which then you could use a remote to tell the server the location of where it hit and then validate it on the server if its close enough.

1 Like

Well yeah theoretically you could do that but it isn’t really performance efficient and also if you were to use remote events you probably would have to protect them so exploiters can’t abuse them. Events which spawn parts serversided pose a big threat because paramters would be position etc. and that would mean that exploiters could potentially even crash/ruin the experience.

1 Like

Fair, so yeah best to do a raycast. But I’ve also done something simular to where I used a raycast on client, and then once the raycast was close enough to a part I would remote event to the server which would then check the parts location on server and then client, and if its a major diff it would not do anything, however if its like a small diff (1-3 studs ping latency), then it would do stuff.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.