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!