Placement system not updating for client

not sure what i’m doing wrong. i’m creating a placement system but its not updating the CFrame for the object in my renderstepped function.

module:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local UserInputService = game:GetService("UserInputService")

local IsServer = RunService:IsServer()
local Assets = require(ReplicatedStorage.Scripts.AssetsModule)

local Placement = {}
Placement.__index = Placement

function Placement.new(plot)
	local self = setmetatable({}, Placement)

	self.Object = nil
	self.GridUnit = 1
	self.Surface = Enum.NormalId.Top

	if IsServer then
		print("Server")
		self.PlotObjects = Instance.new("Folder")
		self.PlotObjects.Name = "PlotObjects"
		self.PlotObjects.Parent = plot
	else
		print("Client")
	end

	return self
end

function Placement:CreateClientRender()
	self.Object = Assets.Blocks.BlockTemplate
	local Object = self.Object:Clone()
	Object.Parent = workspace
	self.Object.Transparency = 0.5
	self.Object.CanCollide = false
	self.Object.CanQuery = false
end

return Placement

client:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local Scripts = ReplicatedStorage:WaitForChild("Scripts")
local Placement = require(Scripts.Placement)

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

Placement:CreateClientRender()

RunService.RenderStepped:Connect(function()
	local MouseCFrame = mouse.Hit
	if Placement.Object then
		Placement.Object.CFrame = MouseCFrame
	end
end)

Can you please add print statements within the RenderStepped function?
Ideally, please print the value of Placement.Object after line 13, and optionally MouseCFrame within the if statement.

1 Like

thanks for your help Sear !
i added a print statement where u said so this is what i’m getting rn:

		print("foo", PlacementModule.Object, MouseCFrame)

I think I see what the issue is - you never actually moved Placement.Object into workspace.
Instead, you move a clone of Placement.Object into workspace. When you update the CFrame, you are changing the position of Placement.Object rather than the cloned object.

One way to fix this issue is to modify the Placement:CreateClientRender() function like this:

function Placement:CreateClientRender()
	self.Object = Assets.Blocks.BlockTemplate
	
	self.VisibleObject = self.Object:Clone()
	self.VisibleObject.Parent = workspace

	self.Object.Transparency = 0.5
	self.Object.CanCollide = false
	self.Object.CanQuery = false
end

then modify the RenderStepped function to be this:

RunService.RenderStepped:Connect(function()
	local MouseCFrame = mouse.Hit
	if Placement.VisibleObject then
		Placement.VisibleObject.CFrame = MouseCFrame
	end
end)

These modifications means you can access the cloned object, rather than the reference object.
(you may need to make a couple of other changes, but this should give you the rough idea of how to fix it)

1 Like

oh yeah i just noticed. i’m not used to working with OOP so that kind of threw me off a bit. thanks a million for your help mate, i appreciate it a lot :open_hands: :v:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.