Hello,i am new to the dev forum and i have a problem with welding a player to another player.
In my game you become a giant and one of the abilites is to grab a normal player in your hand and then either throw them or put them on your back.
The problem is that when i weld the grabbed player to the main player’s hand and then the grabbed player dies,the main player dies along with him.
The welding script looks like this:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PlayerGrab = ReplicatedStorage.PlayerGrab
PlayerGrab.OnServerEvent:connect(function(player,part,Type)
if Type == "Grab" then
local Weld = Instance.new("Weld",part.Parent.UpperTorso)
Weld.Part1 = player.Character.RightHand
Weld.Part0 = part.Parent.UpperTorso
Weld.C0 = CFrame.new(0,0,1.5) * CFrame.Angles(math.rad(90),0,0)
part.Parent.Humanoid.PlatformStand = true
part.Parent.Stun.Value = true
end
end)
I tried deleting the weld when the grabbed player dies,however it doesn’t achieve anything.
Interesting. While I’m not 100% sure why the other player is dying (thank you for another mysterious bug, Humanoid Instance), I’d suspect that :BreakJoints() is being called on the smaller player’s character. If the script to remove the weld was server side then it may not reach the client before it breaks every joint, including those in the bigger player. Just a hunch, but what if you remove the weld then call wait(0.5) before the player dies? Or are you doing all of this on the character death event anyways so the weld will always be removed after death?
After messing around a bit I figured out a solution, what you want to do is set the humanoid’s death state of the Character who is grabbing to false whenever the grabbed Character dies
my server script (slightly different than yours as I had to code grabbing and such)
local Players = game:GetService("Players")
local Event = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
function Enlarge(Char)
local Humanoid = Char:FindFirstChild("Humanoid")
if Humanoid then
Humanoid.BodyDepthScale.Value = 3
Humanoid.BodyHeightScale.Value = 3
Humanoid.BodyWidthScale.Value = 3
Humanoid.HeadScale.Value = 3
end
end
function Grab(Player, Target)
local Char = Player.Character
local Weld = Instance.new("Weld", Target.UpperTorso)
Weld.Part1 = Char.RightHand
Weld.Part0 = Target.UpperTorso
Weld.C0 = CFrame.new(0,0,1.5) * CFrame.Angles(math.rad(90),0,0)
Target.Humanoid.Died:Connect(function()
if Target.Humanoid.Health <= 0 then
Char.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead, false)
Weld:Destroy()
end
end)
Target.Humanoid.PlatformStand = true
end
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Char)
Enlarge(Char)
end)
end)
Event.OnServerEvent:Connect(Grab)
The code for humanoid dying
Target.Humanoid.Died:Connect(function() -- Target is the Grabbed Character
if Target.Humanoid.Health <= 0 then
Char.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead, false) --Char is the Character Grabbing
Weld:Destroy()
end
end)