Ive found this script from a roblox tutorial (as im trying to learn welding ect) that works flawlessly, but how do i make it acheive the same thing but when the player unequipped their tool and not when they join.
local PS = game:GetService('Players')
local SS = game:GetService('ServerStorage')
local referenceDummy : Model = SS.ReferenceDummy
local function weld(partA : BasePart, partB : BasePart, offsetCFrame : CFrame)
partA.CFrame = partB.CFrame * offsetCFrame
local weldConstraint = Instance.new('WeldConstraint')
weldConstraint.Part0 = partA
weldConstraint.Part1 = partB
weldConstraint.Parent = partA
end
local function onCharacterAdded(character : Model)
local newWeld = referenceDummy.AK:Clone()
local weldPart = character:WaitForChild(newWeld.WeldPart.Value.Name)
weld(newWeld, weldPart, newWeld.WeldPart.Value.CFrame:Inverse() * newWeld.CFrame)
newWeld.Parent = character
end
PS.PlayerAdded:Connect(function(player : Player)
player.CharacterAdded:Connect(onCharacterAdded)
end)
for i, player in pairs (PS:GetPlayers()) do
player.CharacterAdded:Connect(onCharacterAdded)
if (player.Character) then
onCharacterAdded(player.Character)
end
end
local SS = game:GetService('ServerStorage')
local Tool = script.Parent
local Character = Tool.Parent -- idk this might change if this isnt a tool script ill just assume it is
local referenceDummy : Model = SS.ReferenceDummy
local function weld(partA : BasePart, partB : BasePart, offsetCFrame : CFrame)
partA.CFrame = partB.CFrame * offsetCFrame
local weldConstraint = Instance.new('WeldConstraint')
weldConstraint.Part0 = partA
weldConstraint.Part1 = partB
weldConstraint.Parent = partA
end
Tool.Unequipped:Connect(function()
local newWeld = referenceDummy.AK:Clone()
local weldPart = Character:WaitForChild(newWeld.WeldPart.Value.Name)
weld(newWeld, weldPart, newWeld.WeldPart.Value.CFrame:Inverse() * newWeld.CFrame)
newWeld.Parent = Character
end)