Weld Player to floor and prevent movement

Hi there,
I am currently making a train, and I want all players to be welded to the floor before it starts, as I don’t want them running around and jumping while it moves. The problem is, if they are jumping when I enabled the welding function, they can glitch it effectively breaking the train. This is a gif of the issue: https://gyazo.com/02d190be5b4071ef5d03763aedd47886

Here is my weld module:

local train = workspace.Train1
local initialized = false
local func --for the touch event
local plrs = {}
local trainStatus = false
local TrainWeldModule = {}
	function TrainWeldModule.WeldPlayers()
		trainStatus = true
		print("Set to true")
		if initialized then return end
		initialized = true
		print("Initialized")
		for i,v in pairs(train:GetDescendants()) do
			if v:IsA("BasePart") and v.Name == "Base" then
				func = v.Touched:Connect(function(p)
					if p.Parent:FindFirstChild("Humanoid") and trainStatus then
						if not p.Parent.LeftFoot:FindFirstChild("TrainWeld") then
							print("WELDING")
							p.Parent.Humanoid.PlatformStand = true
							p.Parent.HumanoidRootPart.Anchored = true
							local preWeld = p.Parent.HumanoidRootPart.CFrame
							local weld = Instance.new("Weld")
							weld.Part1 = p.Parent.HumanoidRootPart
							weld.Part0 = v
							weld.Name = "TrainWeld"
							local val = v.CFrame:Inverse() * preWeld
							weld.C0 = val
							weld.Parent = p.Parent.HumanoidRootPart
							p.Parent.HumanoidRootPart.Anchored = false
							local player = game.Players:GetPlayerFromCharacter(p.Parent)
							table.insert(plrs, player)
						end
					end
				end)
			end
		end
		return
	end
	function TrainWeldModule.DestroyWelds()
		trainStatus = false
		for i,v in ipairs(plrs) do
			if v ~= nil then
				local char = v.Character
				if char.HumanoidRootPart:FindFirstChild("TrainWeld") then
					char.HumanoidRootPart.TrainWeld:Destroy()
					char.Humanoid.PlatformStand = false
				end
			end
		end
		plrs = {}
	end
return TrainWeldModule

Any help is appreciated. Thanks!

1 Like

You could try preventing the player from jumping a few seconds before. JumpPower could be set to 0.

While that might be a temp solution, I would assume there is one that is guaranteed to work no questions asked. I know all the elevators out there find a way, but all their code is obfuscated so I can’t even see what method they deploy.

You know, a long time ago I thought I seen a video with a Roblox plane that a user was walking around with it moving, really confused me, but oh well.

Anyways, you could try to check all players on the train and see if they’re in the air before welding.
If they are in the air you could start a coroutine which at first sets the player’s jumppower to 0 before entering a loop that’s waiting for the player to land back on the ground and then weld them.

Once all players are welded then you could have the train move.

The only thing that worries me with the method I just described is resource usage on the server.

1 Like