Sync Unanchored Parts

I’m making a script where basically the player presses R, then everything unanchored on the map becomes anchored, including other players. Which works fine, but when they press R again to unanchor the recently anchored parts, it also works but it does not sync with what the other players see. Basically what I mean is, say another player jumps, then you press R. On your screen the player is frozen mid jump, but on the other players screen they are moving normally. Which is how I want it to work, but while that player is frozen mid jump, if you press R again instead of updating with the other players current position, it basically makes a clone of that player. Which just lands from the jump and stands there.

I was wondering how I could make it so when you toggle it off, other players and parts positions resync.

Heres the code

local AnchoredParts = {}

for _,ert in ipairs(workspace:GetDescendants()) do
	if ert:IsA("Part") or ert:IsA("MeshPart") or ert:IsA("UnionOperation") and ert.Anchored == true then
		table.insert(AnchoredParts, ert)
		print("Inserted ", ert)
	end
end

local BypassedParts = {}
for _,bps in ipairs(Character:GetDescendants()) do
	if bps:IsA("BasePart") or bps:IsA("MeshPart") or bps:IsA("UnionOperation") then
		table.insert(BypassedParts, bps)
		table.insert(BypassedParts, HumanoidRootPart)
	end
end

local FlashtimeParts = {}

--//Data
local FlashTime = false

--//Functions
function ToggleFlashtime()
	if not FlashTime then
		SpeedEvent:FireServer("Enable")
		
		FlashTime = true
		
		for _,anc in ipairs(workspace:GetDescendants()) do
			if anc:IsA("Part") or anc:IsA("MeshPart") or anc:IsA("UnionOperation") then
				if anc.Anchored == false and not table.find(BypassedParts, anc) then
					table.insert(FlashtimeParts, anc)
					anc.Anchored = true
					print("Anchored", anc, "!")
				end
			end
		end
		
	elseif FlashTime then
		FlashTime = false
		print("Toggled Off!")
		SpeedEvent:FireServer("Disable")
		for _,unc in ipairs(workspace:GetDescendants()) do
			if unc:IsA("Part") or unc:IsA("MeshPart") or unc:IsA("UnionOperation") then
				if unc.Anchored == true and table.find(FlashtimeParts, unc) then
					unc.Anchored = false
					print("UnAnchored ", unc, "!")
				end
			end
		end
	end
end

Help would be appreciated.

1 Like

Is this a LocalScript? Try using RemoteEvent to see if it works. I also recommend putting all of your parts into a folder in the workspace so you can use https://education.roblox.com/en-us/resources/pairs-and-ipairs-intro to easily anchor/unanchor everything without extra codes.

It is a local script, it’s all client sided, I just want to know how I can make it so when they unanchor the parts it syncs the position of everything with what the other players see

On the client, try:

  • Instance:Clone() the parts
  • Hide the original parts (the positions will still replicate to the client in the background)
  • Make the cloned parts fall apart
  • Delete the cloned parts
  • Show the original parts

Of course, if there are a lot of cloned parts, you’ll have to do a lot more than that. You’ll have to get the server to send the client a table of CFrames that the client can apply to their Workspace. This is quite hard, and I don’t know if physics would still work either.

You could try adding a CFrame value into each player so that when the player presses R again, the player will teleport back using the CFrame value to the moment they are frozen. When teleporting them back, make sure it’s a RemoteEvent.

Oh, I mean I want it to sync to what other players see. Like if you presssed R to toggle it off, you would see players in the position they see on their screen. Like basically have the client update back to what the server sees

In that case, have a script for the server to listen for a remote event. Let the ServerScript collect the CFrame of the players and have the ServerScript teleport them from there. This should update for all players.

Would it just be possible to invoke the server for their positions then update them on the client? If so how would I do this?