Attach player to tweening model

Hello.
I’ve made a train that uses TweenService to move, but when players are not seated and are standing, they glitch out when the train starts moving. (can be seen on a video bellow)

I am certain that I need to somehow weld the player to the train (PrimaryPart of tweening), but I have no idea how to do that. Any help would be appreciated.

1 Like

I honestly don’t know how to do this, but how about increasing the player’s Torso/HumanoidRootPart?

Yeah if you use TweenService to move the train, since it’s physics less the force of the train doesn’t transfer onto the players hence the players don’t move. To solve this I suggest looking at EgoMoose’s CustomCharacter Controller script which replicates the character movements onto CFramed objects

If it works for this plane it should work for your train.

2 Likes

Well okay, but is there any instructions within the script? Just seeing the script probably won’t help me at all. I also want this script to work only in certain areas. I think’d rather use the weld method. I know it is possible to do it somehow, but I have no idea how.

Yeah it’s a bit complicated but further research into the attached linked in that thread leads to some interesting answers especially this one:

Also script is included and the mechanism seems like it does raycasting to detect the floor then it does relative CFraming stuff.

I’ve also managed to extract a part of code used in elevator, I guess that could help too. But I need to understand that one myself:

local function attachPlayers()
	local plist = {}
	local r3 = Region3.new(script.Parent.Car.Base.Position-Vector3.new(7,0,7),script.Parent.Car.Base.Position+Vector3.new(7,8,7))
	for i, p in pairs(workspace:FindPartsInRegion3(r3,script.Parent,math.huge)) do
		local pl = game.Players:GetPlayerFromCharacter(p.Parent)
		if (pl ~= nil) then
			table.insert(plist,pl)
		end
	end
	for i, p in pairs(plist) do
		p.Character.Parent = script.Parent.Car.Players
		local plr = p.Character:FindFirstChild("HumanoidRootPart")
		plr.Anchored=true
		plr.Parent.Humanoid.WalkSpeed=0
	end
end

local function detachPlayers()
	for i, p in pairs(script.Parent.Car.Players:GetChildren()) do
		p.Parent = workspace
		local pl = game.Players:GetPlayerFromCharacter(p.Parent)
		local plr = p:FindFirstChild("HumanoidRootPart")
		plr.Anchored=false
		plr.Parent.Humanoid.WalkSpeed=16
	end
end
1 Like

From my understanding, that would basicaly add the player into the Train group and Tween it along.

Yep, the script you posted above just does this:

  1. Get players in the elevator using region 3 and put them in a table

  2. For the players in the elevator, Anchor each of the player’s humanoid root part and set the walk speed to zero so they can’t move, then groups them with the moving object that is being tweened which is the script.Parent.Car

  3. Then for the detach process it undoes what step two does.

Then I believe as you mentioned the player is tweened along with the elevator, seems like it’ll work if you don’t want the players to move around the train.

Well, in the end, I have solved this using ludicrously primitive code:

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local char = hit.Parent
		local RootPart = char:WaitForChild("HumanoidRootPart")
		local Weld = Instance.new("WeldConstraint", workspace)
		
		Weld.Part0 = RootPart
		Weld.Part1 = script.Parent
	end
end)

Only issue is that it doesn’t unweld / destroy weld, after the train has came to halt. Do you know how to fix that? @dthecoolest

Use body movers or body position
You can connect to the body position finish event before changing the posiyio nto the next position.

Using the roblox physics the actual engine will move the characters for em.

Just :Destroy() them after the train has finish Tweening which is when it halts.

Refer to dev API for tweening events.

tween1.Completed:Connect(function(playbackState)
--destroy weld
)

Well yeah, I tried that. Here’s the script:


script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local char = hit.Parent
		local RootPart = char:WaitForChild("HumanoidRootPart")
		local Weld = Instance.new("WeldConstraint", char)
			if game.Workspace.TransitSystemSet.TransitSystem.IsInMotion.Value == true then
		Weld.Name = "Svar"
		Weld.Part0 = RootPart
		Weld.Part1 = script.Parent
		
			elseif game.Workspace.TransitSystemSet.TransitSystem.IsInMotion.Value == false then
		
		Weld:Destroy()
			
		end
	end
end)

Main thing is that even tho the “IsInMotion” value updates, it does not make the weld break (More in linked video), @dthecoolest

2 Likes

I’m not exactly sure how, but I remember hearing a small tip regarding something like this. In the game Portal 2 by Valve, there happens to be a moving room. The developers have said that they made a “Fake room” with all of the colliders and put the player in the Fake room. They then put the player’s camera into a decoy player, which was inside of the moving room. You can then control the decoy player’s position by moving it relative to the tram. Not sure how this would do for animations or how smooth it would be, though.

1 Like

Seeing as nothing has been found for you, I will repost this thread that was already posted as it seems you didn’t read it…

Take a look at the code. There will be a few errors in it when you run it, so fix those, and make sure to bind the died event outside of the heartbeat function.
I’d also reccommend changing the

if Part.Name == "name" then

to

if Part:IsDescendantOf(workspace.Train --[[example path]]) then

This should work fine for you without any weird issues from things like bodymovers etc, and it performs well.

I’ve read that, but I didn’t understand it much. I will try to look at it one more time…

Well. I’ve gone through the code, and I’ve read the post from Kord_K, but I still don’t understand, I am not much of a scripter, how it works. You’ve also said something about changing if Part.Name to Part:IsDescendantOf, and “died” event, and I have no idea what to do about it. Further help would be very appreciated.

Here is a place with all the things I suggested in it. I highly recommend pasting code from the devforum into studio to see where everything goes with formatting and syntax highlighting, then running the game and seeing what doesn’t work and what does work.
Change the path of workspace.Train to whatever the path to your train is.

if Result and Result.Instance:IsDescendantOf(workspace.Train -- [[CHANGE THIS]]) then

Hopefully this helps.
Baseplate.rbxl (22.6 KB)

1 Like

@Styre_x Well, this made the character able to walk in the train. But caused another glitch. The train sustains from multiple parts, and whenever I step on different one, the character glitches, sometimes falls through floor, and sometimes it even teleports the whole train somewhere else. Also, if the player dies, the script stops working. Sorry to bother you again, but I want the train to work properly.

Video footage of the glitch: