TL;DR: If you instead want to skip the contexts you can watch the video to get a visual representation.
Quick Context:
I currently made a shield that is welded to a characters Torso. I originally used TweenService (On the serverside after firing a remote event from the client whenever the client right click’s) to not only repeatedly change the color of this welded shield but also the size of it.
The Issue:
After experimenting with my testers, for some reason we noticed that whenever we used our shields, on our ends, it would look and work perfectly fine from our own perspectives. However, it wasn’t being properly replicated to every other client. It was though, and I confirmed this, being properly replicated to the server but with the exception of it replicating for every other client. On every other clients end it would appear as if the player, that is using the shield, is always anchored from their perspectives and it is only until they stop using the shield that the server finally replicates where they are really positioned, and them properly moving.
My Attempts To Fix It:
After I removed the tween that was resizing the part indefinitely and left only the tween that was changing the color of the shield, it was finally replicating correctly to everyone else. I tried to make my own indefinite tween by creating the resize script manually through RunService like this. Keep in mind that I am using the HEARTBEAT event.
local switch = true
shieldSize = RNS.Heartbeat:Connect(function()
local add = Vector3.new(0.04,0.04,0.04)
if switch then
if shield.Size.Magnitude >= Vector3.new(9,9,9).Magnitude then
switch = not switch
end
shield.Size += add
else
if shield.Size.Magnitude <= Vector3.new(7,7,7).Magnitude then
switch = not switch
end
shield.Size -= add
end
end)
Unfortunately because I used Heartbeat, it was still causing the same issue as if i was using the TweenService to resize this part. It was until I used PreSimulation that everything was finally replicating as it should be. Here’s the updated code:
if isBlocked then
local switch = true
shieldSize = RNS.PreSimulation:Connect(function()
local add = Vector3.new(0.04,0.04,0.04)
if switch then
if shield.Size.Magnitude >= Vector3.new(9,9,9).Magnitude then
switch = not switch
end
shield.Size += add
else
if shield.Size.Magnitude <= Vector3.new(7,7,7).Magnitude then
switch = not switch
end
shield.Size -= add
end
end)
shieldColor:Play()
script.Parent.Parent:WaitForChild("Shield").Transparency = 0.5
else
shieldSize:Disconnect()
shieldColor:Pause()
script.Parent.Parent:WaitForChild("Shield").Transparency = 1
end
Video Using TweensService To Resize (Same as Heartbeat): < Doesn’t Work
Video using PreSimulation via Runservice (Finally Works!). < Works
Can any advanced programmer tell me why this is working .