Alternative to tweening? Help!

Goal:
I want to be able to move a part down from the sky and detect hits on the player on the server rather than the client.

Issues:
I am currently tweening the part on the client which means that hit detection is not stable. I want to be able to detect the hits on the server. However tweening it on the client means that the position on the server wont update meaning I can’t do hit detection.

My thoughts:
Find an alternative to tweening where I can detect hits on the server whilst handling the physics on the client.

Any help or feedback is appreciated. This has been bugging me for ages.
Thanks.

(I can provide any screenshots, information or code where necessary)

2 Likes

I could be wrong, but any value changes made on the client are not replicated automatically. If you really only want to tween on the client but still want hit detection on the server I would use a remote event to parse the position and size of what youre tweening to the server and calculate if a part is in that hit range or not. You can handle it alongside the tween seperately or using the lerp function and a for loop you can tween the movement yourself and send the information to the server each frame of the tween.

3 Likes

Is this not really bad for performance? This would be sending around 60 remote events a second per player.

2 Likes

Any game logic that must be replicated shall be implemented on the server - otherwise you’re just asking for your game to be exploited

2 Likes

Unless it’s some building system - you’d have to add sanity checks though.

3 Likes

It is, but if you want to replicate the tween on the client only then the server doesnt even know where the part youre trying to detect colissions for is. You have to tell it that.

What are you trying to detect the colission for? If its something like a bullet you could just cast a ray from the source to the end goal of the client tween and kill anything on that ray (example) (only 1 event fired)

Or if its someting larger but slow moving you can send every other frame or every 3 frames depending on how slow it is.

2 Likes

currently the parts are created on the server every x amounts of seconds. they are then tweened down to their destination. the way this is done is by remote event firing to all clients and passing the part and destination position as a parameter and then tweening it.

2 Likes

its a big part, not a bullet. its slow moving - takes about 1.5 seconds to reach destination.

I see, if its a linear tween you can use a ray and a single remote event. Parse the origin and cast a ray down, if a player hits that ray you know theyre in the line of sight of that tween. Use the time for the tween to add a delay e.g. delay - delay * 0.9 for that check otherwise players will be detected even if the part is way above them.

You can add to this method by parsing a radius in and if a player is detected on the ray, wait the delay time then check if they are in that radius. That way you can have a colission area as opposed to a line (since you said the object is quite large).

But based on the example youve given I dont see why you arent handling tweens on the server?

I’m not sure if lerping is any different but you can try that.

Alternatively, you can use fireallclients which I think is the closest you can get to the goal.

by linear tween you mean in a straight line? im not handling it on the server because tweening on the server just puts unnecessary strain on the server and looks very choppy.

1 Like

If your server tweens are looking choppy its a sign that your game might need some optimisation, but I digress yes I mean straight line.

“Help with my flower” alternate universe:

2 Likes

i dont think optimisation has anything to do with it. i can make a blank baseplate and tween a random part on the server then it will still look choppy.

Fair enough, yeah id go with the raycast, delay, check radius solution I mentioned.

1 Like

Ok thankyou for the help. Really appreciated!

so for the ray method am i casting the ray on the client? then once i detect a hit after waiting the delay i am firing a remote event back to the server?

Cast on the server, check for players, if players found wait delay then check for characters within a radius

All of that should happen on the server, only 1 remote event per falling object.

1 Like

Maybe something like this. Not totally sure how you’re doing anything as you posted no scripts.

local part = workspace.Part
local rns = game:GetService("RunService")
local targetPosition = Vector3.new(10, part.Position.Y, part.Position.Z)
local speed = 1

rns.Heartbeat:Connect(function()
	if part.Position.X < targetPosition.X then
		part.Position = part.Position + Vector3.new(speed * rns.Heartbeat:Wait(), 0, 0)
	end
end)

Have you tried a Prismatic Constraint?

It will move your part smoothly in a straight line (on the server) and will not have issues with collision detection.