Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago
Edited 6 years ago

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)`
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. NikkoTheJesusMan 3 — 6y
0
Have you tried making it into a function when changing the size and anchoring it while redoing the weld? seith14 206 — 6y
0
Please stop making your question titles all caps. M39a9am3R 3210 — 6y
0
@M39a9am3R NO. NikkoTheJesusMan 3 — 6y
View all comments (3 more)
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 NikkoTheJesusMan 3 — 6y
0
Alright... I can start adding notes to your questions until you stop putting your titles in all caps. M39a9am3R 3210 — 6y
0
@M39a9am3R why does it matter in the first place though? Seems like you’re just being petty for no reason NikkoTheJesusMan 3 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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
0
it works! thanks :) NikkoTheJesusMan 3 — 6y
Ad

Answer this question