So my problem is that I have two modules for client & server. When the server updates it’s values, it sends a remote for the client side to replicate those values. However, the values on the client side don’t match up with the serverside values.
The "TotalAttachParts" value in the client doesn't replicate to the values that the server currently has, but instead replicates the previous values it had before the value changed.
This is really my only problem, and I can't figure out why.For more context, basically the attachparts of a block are supposed to appear when u place it down. Although the attachparts are seen to be invisible, unless you place another block, then the previous attachparts will appear.
I’ll have a video
at the very bottom to show you what my bug looks like.
If you’re wondering what the attachparts
are, it’s basically just the orange dots on the blocks I’m placing down in the video
Server
function BuildServiceServer.PlaceBlock(self: BuildServiceServer, player: Player, blockName, placementInfo)
-- just gets the values needed
local char = player.Character or player.CharacterAdded:Wait()
local player_Folder = char.Parent
local blockFolder = player_Folder:FindFirstChild("BlockFolder")
local block = blocks:FindFirstChild(blockName)
if not block then return end
block = block:Clone()
if not self:placeable(block, placementInfo) then return end
local inputPart: Part = block:FindFirstChild("InputPart", true)
--print(placementInfo)
-- checks if mouse is hovering over a part that can be interacted with
if CollectionService:HasTag(placementInfo.MouseObject, "AttachPart") then
CollectionService:AddTag(placementInfo.MouseObject, "AttachPartTakened")
local id = HttpService:GenerateGUID(false)
block:SetAttribute("AttachmentId", id)
placementInfo.MouseObject:SetAttribute("AttachmentId", id)
self.AttachPartsTakened[id] = placementInfo.MouseObject
end
[[-- Just some extra stuff that isn't important to the main problem
block.PrimaryPart = inputPart or block.PrimaryPart
block:PivotTo(placementInfo.CFrame)
block.Parent = blockFolder
block:SetAttribute("OwnerId", player.UserId)
table.insert(self.Objects, block)
self.TotalAttachParts = self.TotalAttachParts
Debris:AddItem(inputPart, 0)
]]
-- These two functions are relatively important for the data, so They're provided under this function
self:AddAttachparts(block)
self:SetValue(player)
end
[[--
This function updates the table, "TotalAttachParts". I don't understand why it
aint working since there shouldn't be any bugs with this function.
]]
function BuildServiceServer.AddAttachparts(self: BuildServiceServer, block)
for _, object in block:GetDescendants() do
if CollectionService:HasTag(object, "AttachPart") then
if not table.find(self.TotalAttachParts, object) then
table.insert(self.TotalAttachParts, object)
end
end
end
end
-- This function is what replicates the tables to the client
function BuildServiceServer.SetValue(self:BuildServiceServer, player)
local returnInfo = {
Blocks = self.Objects,
AttachPartsTakened = self.AttachPartsTakened,
TotalAttachParts = self.TotalAttachParts
}
BuildRequest:FireClient(player, returnInfo)
end
Client
function BuildServiceClient.clientReceiverUpdater(self: BuildServiceClient,returnInfo: {})
self.Blocks = returnInfo.Blocks
self.TotalAttachParts = returnInfo.TotalAttachParts
self.AttachPartsTakened = returnInfo.AttachPartsTakened
--print(#returnInfo.TotalAttachParts, "Client")
--print("Blocks = ".. #BuildServiceClient.Blocks, "AttachedParts =", BuildServiceClient.AttachPartsTakened, "TotalAttachedParts = ".. #BuildServiceClient.TotalAttachParts)
self:updateAttachments()
end