-
What do you want to achieve?
I am currently developing an automatic train game and I want to ensure that when the train is in motion, a player is welded to a part that is welded to the train and that as the player is welded, the user is moving with the train. -
What is the issue?
Currently, the player is not welded to the part I want it to be welded to nor is the player moving along with the train. I tried adding a weld script to my script but the train still ends up leaving the player behind and the player is not welded to the intended part. For reference, here is a YouTube link containing a 3-second clip illustrating the issue (note that the translucent red brick is the part I intend to weld the player to): https://youtu.be/d35bmjzQ-eQ -
What solutions have you tried so far?
I have tried importing some weld scripts on devforum and using the if-then command to find the player’s HumanoidRootPart and then anchoring that to the intended part but to no avail.
To summarize everything:
The train will wait 2 minutes at its current position for players to get on. The part that I intend to weld the player to on the train is called “SensorPart” (this part is already welded to the primary part that is tweening the train). After 2 minutes, the door closing announcement plays (which is defined as the local variable “announce” in the script) and 2 seconds after the completion of the announcement, that’s when I want the weld script to be activated before the train goes into motion. Once the train has reached its destination, the player should no longer be welded to “SensorPart.”
Note: I do not want the player to move freely whilst the train is in motion.
Now, I am an absolute novice at programming. I’m more of a developer than I am a scripter so your input and support are highly appreciated.
local TweenService = game:GetService("TweenService")
local train = workspace.Tweentrain
local modelroot = train.Door1
local announce = workspace.Sound1
local base = train.SensorPart
local infohangar = TweenInfo.new(8, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
local infoturn = TweenInfo.new(0.75, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
local Fromdepot = TweenService:Create(modelroot, infohangar, {
CFrame = CFrame.new(11, 7.5, -217)
})
wait(120)
announce:Play()
wait(0.1)
base.Touched:Connect(function(p)
if p.Parent:FindFirstChild("Humanoid") then
print('Player is on the floor')
local weld = Instance.new("WeldConstraint")
weld.Part0 = p.Parent.HumanoidRootPart
p.Parent.HumanoidRootPart.Anchored = true
print('Player is now welded to the train')
end
end)
Fromdepot:Play()
Fromdepot.Completed:Wait()
wait(0)
local TurnRight = TweenService:Create(modelroot, infoturn, {CFrame = CFrame.new(Vector3.new(11.208, 7.5, -221.773)) * CFrame.Angles(0,math.rad(-5),0)})
base.Touched:Connect(function(p)
if p.Parent:FindFirstChild("Humanoid") then
print('Player is on the floor')
local weld = Instance.new("WeldConstraint")
weld.Part0 = p.Parent.HumanoidRootPart
p.Parent.HumanoidRootPart.Anchored = false
print('Player is no longer welded to the train')
end
end)
TurnRight:Play()
TurnRight.Completed:Wait()