So I'm attempting to use a RemoteEvent to tween a joint from a server script and the loop steps 1/60th of a second because it's connected to RenderStepped, but for some reason the function that tweens the joint tweens the joint in a very choppy manner instead of smoothly like how I want it to run, is there any reason for this? Or do RemoteEvents just not work with RenderStepped? Thanks.
Here's the remoteEvent code:
local lerpCF = script:WaitForChild("lerpCF") function lerpCF.OnServerInvoke(_, Joint, Prop, startCF, endCF, Alpha) Joint[Prop] = startCF:lerp(endCF, Alpha) end
Here's a tweenJoint code:
function tweenJoint(Joint, newC0, newC1, Alpha, Duration) spawn(function() local newCode = math.random(-1e9, 1e9) local tweenIndicator = createTweenIndicator:InvokeServer(Joint, newCode) if Duration <= 0 then if newC0 then Joint.C0 = newC0 end if newC1 then Joint.C1 = newC1 end else local Increment = 1.5 / Duration local startC0 = Joint.C0 local startC1 = Joint.C1 local X = 0 while true do RS.RenderStepped:wait() local newX = X + Increment X = (newX > 90 and 90 or newX) if tweenIndicator.Value ~= newCode then break end local T = tick() if newC0 then lerpCF:InvokeServer(Joint, "C0", startC0, newC0, Alpha(X)) end if newC1 then lerpCF:InvokeServer(Joint, "C1", startC1, newC1, Alpha(X)) end print(tick() - T) --This prints some number near 0.03, which slows down the loop if X == 90 then break end end end deleteTweenIndicator:InvokeServer(tweenIndicator, newCode) end) end
Your problem is latency. It's always a bit laggy looking when you tell server to create an instance (well more like an instance that gets affected by physics) which needs to get replicated to all the clients. You should be handling this client side.
SERVER
function lerpCF.OnServerInvoke(...) lerpCF:InvokeAllClients(...) -- apparently there's no such function but as stated on the last line, you should use a RemoteEvent end
CLIENT
lerpCF.OnClientInvoke = function(otherplr,Joint, Prop, startCF, endCF, Alpha) if otherplr ~= localplayer then -- we don't want to duplicate the animation --you might want to check if the target of animating is close enough to animate or just lower the quality depending on the distance ----animate end end while true do RS.RenderStepped:wait() --tell server to tell other machines to animate the exact same way --animate this client's side because it's the most important end
I use this method with projectiles and other visual stuff. It allows easy manipulating to the replicated object depending on the distance and other variables.
Also that's RemoteFunction, you aren't returning anything so I'd suggest using an event instead.