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)
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.
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.
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.
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?
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.
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.
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?
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)