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.
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.
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
Get players in the elevator using region 3 and put them in a table
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
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)
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)
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.
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.
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
@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.
In that case, make it set the Train variable to the train’s primarypart, and hopefully that fixes it. If you don’t have a primarypart set, set it to the bottom floor.
That just made it worse. I really think I would like the most the solution, where player is atatched to the floor, unable to move. After all, that’s what I originaly wanted to achieve. I managed to do that, but the player wouldn’t get unatatched. (more info in Reply 13 and 14)