Is it possible to use local scripts for Prismatic Constraints?

Hello, I am a beginner in scripting. I attempted to use a local script to handle moving platforms, but my knowledge is limited :sweat:.

  1. What do you want to achieve?
    A moving platform that uses Prismatic Constraints. When the client touches it, the platform will only move for the client and no one else.

  2. What is the issue?
    Upon touching (using local script), after a delay, it moves for all clients. Expected behavior for scripts.

  3. What solutions have you tried so far?
    Run Service seems like a good idea, but I dont know how to best utilize it. I want to see if its possible to not use remote events to minimize lag.

Here’s the model link for anyone to try: MovingPlatform - Roblox

Script 1: Uses a script for server usage

local Players = game:GetService("Players")

local start = script.Parent:WaitForChild("Start");
local finish = script.Parent:WaitForChild("Finish");
local Platform = script.Parent:WaitForChild("MovingPart")

local DefaultPos = Platform.CFrame
local PrismaticConstraint = Platform:WaitForChild("PrismaticConstraint")
local Speed = Platform:WaitForChild("Speed")
PrismaticConstraint.Velocity = 0

local forward = false
local Moving = false

local function PlatformStart(hit)
	if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") and Moving == false then
		local player = Players:GetPlayerFromCharacter(hit.Parent)
		if player then
			Moving = true
			PrismaticConstraint.Velocity = Speed.Value
		end
	end
end
Platform.Touched:Connect(PlatformStart)

local function FinishTouch(hit)
	if hit == Platform and forward == false then
		forward = true
		PrismaticConstraint.Velocity = -Speed.Value
	end
end
finish.Touched:Connect(FinishTouch)

local function StartTouch(hit)
	if hit == Platform and forward == true then
		forward = false
		PrismaticConstraint.Velocity = Speed.Value
	end
end
start.Touched:Connect(StartTouch)

Script 2: An attempt for local script in StarterPlayerScripts

local Players = game:GetService("Players")
local CollectionService = game:GetService("CollectionService")

for _, inst in pairs(CollectionService:GetTagged("MovingPlatform")) do
	if inst then
		local start = inst:WaitForChild("Start");
		local finish = inst:WaitForChild("Finish");
		local Platform = inst:WaitForChild("MovingPart")

		local DefaultPos = Platform.CFrame
		local PrismaticConstraint = Platform:WaitForChild("PrismaticConstraint")
		local Speed = Platform:WaitForChild("Speed")
		PrismaticConstraint.Velocity = Speed.Value

		local forward = false
		local Moving = false

		local function PlatformStart(hit)
			if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") and Moving == false then
				local player = Players:GetPlayerFromCharacter(hit.Parent)
				if player == Players.LocalPlayer then
					Moving = true
					PrismaticConstraint.Velocity = Speed.Value
				end
			end
		end
		Platform.Touched:Connect(PlatformStart)

		local function FinishTouch(hit)
			if hit == Platform and forward == false then
				forward = true
				PrismaticConstraint.Velocity = -Speed.Value
			end
		end
		finish.Touched:Connect(FinishTouch)

		local function StartTouch(hit)
			if hit == Platform and forward == true then
				forward = false
				PrismaticConstraint.Velocity = Speed.Value
			end
		end
		start.Touched:Connect(StartTouch)
	end
end

Unfortunately roblox replicates physics from clients to clients.

You could probably prevent this if, as a setup step when a player first joins, you delete the existing platform on the client and make a copy on the client. Now the client platform and server platforms would be unconnected and impossible to replicate.

That or anchor it and use CFrame and tween service, which wouldn’t replicate.

I would do nothing serverside for this besides maybe setup invisible attachments/parts for the start and end of the platform

locally, I would create the moving platform along with the needed constraints
you can copy it from somewhere like ReplicatedStorage

then, when it is touched, check using :GetAncestorOfClass and :GetPlayerFromCharacter to ensure that the part is touched by the player that owns the part before adjusting the prismatic constraint