How Can I Make A Player Weld To The Part They Touch?

I’m working on a game similar to cart ride games, But the player is in a ball that’s in their character, And there’s a part that moves up and down the player needs to stand on, the only problem is, If the player is laggy they fall through the moving Part.

Im trying to make the player Weld to the part when they touch it, Heres my script,

local Part = script.Parent
local Weld = script.Parent.Weld

Part.Touched:Connect(function(Hit)

	local Player = Hit.Parent
	Weld.Part0.Parent = Player
	
end)

I know its bad im a beginner.

try this

local ball = Instance.new("Part")
ball.Parent = script.Parent
ball.Position = script.Parent.HumanoidRootPart
ball.Anchored = false
ball.CanCollide = true
ball.Massless = true
ball.Shape = Enum.PartType.Ball
local weld = Instance.new("WeldConstraint") 
weld.Parent = ball
weld.Part0 = ball
weld.Part1 = script.Parent.HumanoidRootPart

im confused, do you want the ball to be welded to the character? or parts be welded to the ball once it is touched

This script may help you

local Part = script.Parent

Part.Touched:Connect(function(v1)
if v1.Parent:FindFirstChild("Humanoid") ~= nil then
local weld = Instance.new("Weld")
Weld.Part0 = v1.Parent.Head
Weld.Part1 = Part
end
end)

I want the ball to weld to the Part

alright.

Part.Touched:Connect(function(Hit)
local weld = Instance.new("WeldConstraint")
weld.Parent = ball -- from previous code
weld.Part1 = Hit
weld.Part0 = ball
Hit.Anchored = false
Hit.CanCollide = false
Hit.Parent = ball
end)

This ain’t gonna work that fine, check out How Can I Make A Player Weld To The Part They Touch? - #3 by kittyPGR :slight_smile:

Im confused, am i supposed to Combine this script with the last one?

Nope this one isnt working, it doesnt even give an Error in the output Menu

yeah just uh, combine that previous one I posted with the one I posted on the bottom.
it should look like this

local ball = Instance.new("Part")
ball.Parent = script.Parent
ball.Position = script.Parent.HumanoidRootPart
ball.Anchored = false
ball.CanCollide = true
ball.Massless = true
ball.Shape = Enum.PartType.Ball
local weld = Instance.new("WeldConstraint") 
weld.Parent = ball
weld.Part0 = ball
weld.Part1 = script.Parent.HumanoidRootPart

Part.Touched:Connect(function(Hit)
local weld2 = Instance.new("WeldConstraint")
weld2.Parent = ball -- from previous code
weld2.Part1 = Hit
weld2.Part0 = ball
Hit.Anchored = false
Hit.CanCollide = false
Hit.Parent = ball
end)

try this @KIDDO_SNIPPETS How Can I Make A Player Weld To The Part They Touch? - #3 by kittyPGR

Or you can also refer This Video for more detailed functions