Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

IS THERE A WAY TO CHANGE SIZE OR REPLACE A PART IN A TOOL WITHOUT BREAKING THE WELD SCRIPT?

I am trying to create a larger hitbox of the tool upon pressing the key E. I've tried changing the current hitbox of the tool in the script and I tried replacing the hitbox of the Tool with a hitbox that is bigger but both seem to cause the hitbox to fall off and go through the map.

the current part of the script I have now is:

game:GetService('UserInputService').InputBegan:Connect(function(input, process)
  if input.UserInputType == Enum.UserInputType.Keyboard and not process then
    if input.KeyCode == Enum.KeyCode.E and Player and character and 		Tool.Handle.Value.Value == 1 then
Tool.Handle.Value.Value = 2
game.Debris:AddItem(Tool.Hitbox,0.1)
local chkhitbox = game.ReplicatedStorage.ChakraHitbox:Clone()
chkhitbox.CFrame = Tool.Handle.CFrame
chkhitbox.Parent = Tool
chkhitbox.Name = "Hitbox"

the weld script is

local RbxUtility = LoadLibrary("RbxUtility")
local Create = RbxUtility.Create
local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")

local function Weld(X, Y)
	local CJ = CFrame.nelw(X.Position)
	local C0 = X.CFrame:inverse()*CJ
	local C1 = Y.CFrame:inverse()*CJ
	
	local W = Create("Weld"){
		Name = "Weld",
		Parent = X,
		Part0 = X,
		Part1 = Y,
		C0 = C0,
		C1 = C1
	}
end

local function WeldObjects(parent)
	for i, obj in pairs(parent:GetChildren()) do
		if obj:IsA("Part") or obj:IsA("UnionOperation") then
			Weld(Handle, obj)
			obj.Anchored = false
			-- print("[Weld] Objects have been welded!")
		end
	end
end

Tool.Equipped:connect(function()
	WeldObjects(Tool)
end)

Tool.Unequipped:connect(function()
	WeldObjects(Tool)
end)`

7 comments

0

This is only part of the script I have for the tool... the rest of the script works... just not the changing hitbox part.

0

Have you tried making it into a function when changing the size and anchoring it while redoing the weld?

0

Please stop making your question titles all caps.

0

@M39a9am3R NO.

0

@seith14 not exactly sure what you mean... i tried welding the parts back together during the e function but it didn’t work for some reason although i can try again if that’s what you mean

0

Alright... I can start adding notes to your questions until you stop putting your titles in all caps.

0

@M39a9am3R why does it matter in the first place though? Seems like you’re just being petty for no reason

1 answer

I say just remove the old one after cloning it. That way you get the weld, but don't have too many scripts when you test (or when u play, cuz it lags based on the items in the game).

Here, let me show u (I take it that they are both the same script):

game:GetService('UserInputService').InputBegan:Connect(function(input, process)
	if input.UserInputType == Enum.UserInputType.Keyboard and not process then
		if input.KeyCode == Enum.KeyCode.E and Player and character and Tool.Handle.Value.Value == 1 then
		Tool.Handle.Value.Value = 2
		game.Debris:AddItem(Tool.Hitbox,0.1)

		local chkhitbox = game.ReplicatedStorage.ChakraHitbox:Clone() -- creating the part named "Hitbox"
		chkhitbox.CFrame = Tool.Handle.CFrame
		chkhitbox.Parent = Tool
		chkhitbox.Name = "Hitbox"
		
		script:Clone() -- Remove and clone the old script
		script:Remove()
	end
end

1 comment

0

it works! thanks :)

This discussion is preserved as it was. New answers, comments, and votes are closed.