I’m trying to make a soda jug from ServerStorage “attach” to the player’s UpperTorso, similar to how the backpacks are in games like Bee Swarm Simulator, but for some reason, the jug isn’t welded. It just falls through the baseplate, like it’s welded to nothing.
Here’s the code.
--Variables
local players = game:GetService("Players")
local serverStorage = game:GetService("ServerStorage")
--Attaching jug
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local jug = serverStorage.SodaJug:Clone()
local weld = Instance.new("WeldConstraint")
weld.Enabled = true
jug.CFrame = char:WaitForChild("UpperTorso").CFrame:ToWorldSpace(CFrame.new(Vector3.new(0, 0, 2.894)))
jug.Parent = char
weld.Part0 = char.UpperTorso
weld.Part1 = jug
weld.Parent = char.UpperTorso
weld = nil
jug = nil
end)
end)
There are no errors, and it’s not like the jug doesn’t appear at all, I can see the jug in workspace,but it falls and gets destroyed like it isn’t welded.
What do you want to achieve? I want to weld a part to the player’s torso.
What is the issue? The part appears in workspace, but isn’t attached to the torso, as if it isn’t welded at all.
What solutions have you tried so far? I tried mixing up the order of the code, and tried setting the position instead of CFrame, but nothing worked.
Edit: I’ve noticed that the weld is only briefly parented to the UpperTorso. It strangly gets destroyed for some reason.
That won’t do anything, and will in fact, make the script less efficient. All those lines do is set the unneeded variables to nil, which doesn’t destroy the object they’re assigned to or anything.
weld is a variable. Setting it to nil doesn’t destroy the object it’s assigned to, it just makes it so more memory is available, and I won’t be able to access the object in the rest of the event, nothing else happens.
If this weren’t the case, then I wouldn’t be able to briefly see the jug in workspace.
I’ve just noticed that the weld is only parented to the UpperTorso for less than a second, after that, it seems to be destroyed for some reason. Removing weld = nil didn’t fix it, by the way.
There’s only two scripts in the game, one is a LocalScript, and doesn’t even touch the jug, and the other is a server script, which only creates the jug, and is the script that is broken.
Also, the problem seems to be that the weld only works for less than a second, because it is very shortly destroyed.
It’s successfully welded to the HumanoidRootPart, so the problem must be the UpperTorso. Is there anything in the UpperTorso that might be destroying the weld?