Returning a client-moved part to the original position when server rejects placement

--right now its just 50% chance for accept/reject move i'll fix that later
	if math.random() < .5 then
		print("i accept")
		model:SetPrimaryPartCFrame(cframe)
	else
		print("I reject")
		local lastposition = model.PrimaryPart.CFrame
		model:SetPrimaryPartCFrame(model.PrimaryPart.CFrame * CFrame.new(0,1,0))
		model:SetPrimaryPartCFrame(lastposition)
	end

I have a build system where the player drags around their furniture and then when they’re done a remote event fires and tells the server which furniture model and the its new cframe. Then the server accepts/rejects the change. For rejection, what i’m doing right now is moving the model’s cframe 1 stud and then moving it back to where it was to get that to replicate on the client. This feels a little hacky but it works i guess, whats your thoughts?

I played around in Studio just now for about 20 minutes and couldn’t find a better solution, unfortunately. I don’t think there’s any way to trick the server into replicating lastposition without first replicating a different position. Unless someone has a better idea, sometimes you just gotta comment

-- ew this is hacky

and move on.

EDIT: Hell, the original KOs/Wipeouts leaderboard script made by Roblox has

-- VERY UGLY HACK
-- Will this leak threads?
1 Like

A less hacky method:
Use a RemoteFunction instead of a RemoteEvent. Have the client fire it to the server to give its new cframe. If the server accepts it, have the server return true. Otherwise, have it return false and the lastposition (it can be fetched reliably since the model hasn’t moved on the server). Have the client do the processing and bingo.

3 Likes