Players becoming intertwined when welding

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Players not intertwining.

  2. What is the issue? Include screenshots / videos if possible!
    When welding a lantern to the player, it welds fine. When another player joins, for some reason both players become intertwined. I’m at a loss.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve looked literally everywhere.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local Lamp = script.Parent.Parent:WaitForChild("Lantern")
local Part1 = Lamp:WaitForChild("PrimaryPart")

game.Players.PlayerAdded:Connect(function(player)
		local char = player.Character or player.CharacterAdded:Wait()
		local playername = player.Name

		local weld1 = Instance.new("Weld")
		weld1.Part0 = Part1
		weld1.Part1 = char.UpperTorso
		weld1.Parent = Part1

		for _, Part0 in pairs(Lamp:GetChildren()) do
			if Part0:IsA("BasePart") and not (Part0 == Part1) then
				local WeldConstraint = Instance.new("WeldConstraint")
				WeldConstraint.Part0 = Part0
				WeldConstraint.Part1 = Part1
				WeldConstraint.Parent = WeldConstraint.Part0
				Part1.Anchored = false


				Part0.Anchored = false
			end
		end

		Part1.Anchored = false
		Part1.CanCollide = false

		weld1.C1 = CFrame.new(0.7, -1, 0)
		weld1.C0 = CFrame.Angles(math.rad(180),math.rad(270),math.rad(0))
		local lantPlr = Lamp:Clone()
		lantPlr.Parent = char

	end)

image

Please help!

1 Like

Where’s this script located?
If Lamp = script.Parent.Parent:WaitForChild("Lantern") refers to just one lamp in the game or a folder in the game then you are essentially welding both players to the same lamp when PlayerAdded fires. Normally you’d keep the Lamp in Server or Replicated Storage and then Clone it when a player is added.

This isn’t the solution, but why are you welding all the lamp parts with this script anyway? You can just build the lamp model with the Parts joined by WeldConstraints. You only need to weld the model’s PrimaryPart to the player with your scipt.

2 Likes

The lantern is located in ServerScriptService
image
and I thought that’s what I was doing?

To answer your second question, it was due to an issue before that, I just forgot to get rid of it.

1 Like

Are you just trying to weld the lantern to the player when they equip a tool? Or are you trying to weld the lantern to every single player when they join, and not allow them to drop it or unequip it?

2 Likes

So the lantern isn’t a tool, it’s just a model that I’m trying to weld to every player when they join

1 Like

So store a Lantern model that’s welded together in ReplicatedStorage.
In your script clone a model of the Lantern and weld its PrimaryPart to each player when they join.

1 Like

I managed to do this by welding all of the parts in my lamp model (free asset) before hand in studio.

Then I put a part inside of my lamp where I wanted the player to hold it, I called it handle (even though it isn’t a tool), and I welded it to my lamp.

image

Then I put that lamp in replicated storage, so I could access it from a script later on.

image

Inside of Server Script Service I created a script that cloned a new lamp, positioned it, and welded it to the player.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Lamp = ReplicatedStorage.Lantern

game.Players.PlayerAdded:Connect(function(player)
	local char = player.Character or player.CharacterAdded:Wait()
	local playername = player.Name
	
	-- Creates a new lamp clone
	local newLamp = Lamp:Clone()
	newLamp.Parent = char
	
	-- Positions the lamp
	local Handle = newLamp.PrimaryPart
	Handle.CFrame = char.RightHand.CFrame
	
	-- Welds the lamp
	local weld = Instance.new("WeldConstraint")
	weld.Parent = Handle
	weld.Part0 = Handle
	weld.Part1 = char.RightHand
end)

That’s all it took to weld the lamp to my hand.

You need to weld the cloned lantern to the player, not the original lantern in ServerScriptService, and you don’t need to do script.Parent.Parent:WaitForChild("Lantern") instead do script.Parent since the server doesn’t need to wait for any children that already exists in Workspace and ServerScriptService before the game started and the script is parented to the model.

local Players = game:GetService("Players")
local Debris = game:GetService("Debris")

local Lantern = script.Parent

local function CharacterAdded(Character: Model)
	local LaternClone = Lantern:Clone()
	Debris:AddItem(Lantern:FindFirstChild("Welding"), task.wait()) -- deleting the "Welding" script
	
	local Part1 = LanternClone.PrimaryPart
	
	for _, Part0 in ipairs(LanternClone:GetDescendants()) do
		if (Part0:IsA("BasePart") == true) and (Part0 ~= Part1) then
			local WeldConstraint = Instance.new("WeldConstraint")
			WeldConstraint.Part0 = Part0
			WeldConstraint.Part1 = Part1
			WeldConstraint.Parent = Part0
			
			Part0.CanCollide = false
			Part0.Anchored = false
		end
	end
	
	local RightHand = Character:FindFirstChild("RightHand")
	LanternClone:PivotTo(RightHand:GetPivot() - Vector3.new(0, 1, 0))
	
	local WeldConstraint = Instance.new("WeldConstraint")
	WeldConstraint.Part0 = RightHand
	WeldConstraint.Part1 = Part1
	WeldConstraint.Parent = Part1
	
	Part1.CanCollide = false
	Part1.Anchored = false
	
	LanternClone.Parent = Character
end

local function PlayerAdded(Player: Player)
	local Character = Player.Character
	
	if (Character ~= nil) and (Character.Parent ~= nil) then
		CharacterAdded(Character)
	end
	
	Player.CharacterAdded:Connect(CharacterAdded)
end

for _, Player in ipairs(Players:GetPlayers()) do
	task.spawn(PlayerAdded, Player)
end

Players.PlayerAdded:Connect(PlayerAdded)
3 Likes

I alternatively switched to a ball socket constraint here to make the lamp swinging effect.

image

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Lamp = ReplicatedStorage.Lantern

game.Players.PlayerAdded:Connect(function(player)
	local char = player.Character or player.CharacterAdded:Wait()
	local playername = player.Name
	
	-- Creates a new lamp clone
	local newLamp = Lamp:Clone()
	newLamp.Parent = char
	
	-- Positions the lamp
	local Handle = newLamp.PrimaryPart
	Handle.CFrame = char.RightHand.CFrame
	
	local ballSocket = Handle.BallSocketConstraint
	ballSocket.Attachment1 = char.RightHand.RightGripAttachment
end)
1 Like

Please mark one of these posts as the Solution so people don’t keep trying to solve it.

Thank you! This worked for me, I appreciate the help!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.