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

How can I weld two models together?

Asked by 3 years ago
Edited 3 years ago

Before I get started, the code may be trash, but so far I understand what’s there. If you have any suggestions on how to clean it up or have it run more efficient, let me know. So I’m trying to create a functional forklift. I got the forks to lift up and down. Right now, I can’t figure out how to attach the forks to the pallet so it moves with the forks. I’ve looked around at some forums and haven’t found a method that could work. I may have overlooked a few methods that would work.

local UIS = game:GetService("UserInputService")
local pressed = false
local lFork = workspace.Forklift.Forks.lFork
local rFork = workspace.Forklift.Forks.rFork
local lStart = lFork.Position
local rStart = rFork.Position
local b1 = workspace.Forklift.Forks.Back1
local b2 = workspace.Forklift.Forks.Back2
local b3 = workspace.Forklift.Forks.Back3
local b4 = workspace.Forklift.Forks.Back4
local b5 = workspace.Forklift.Forks.Back5
local b1Start = b1.Position
local b2Start = b2.Position
local b3Start = b3.Position
local b4Start = b4.Position
local b5Start = b5.Position

vKeyPressed = false
gKeyPressed = false

UIS.InputBegan:Connect(function(input, upKey)
    if not upKey then
        if input.KeyCode == Enum.KeyCode.R then
            if not pressed then
                pressed = true
                repeat wait()
                    lFork.Position = lFork.Position + Vector3.new(0,0.15,0)
                    rFork.Position = rFork.Position + Vector3.new(0,0.15,0)
                    b1.Position = b1.Position + Vector3.new(0,0.15,0)
                    b2.Position = b2.Position + Vector3.new(0,0.15,0)
                    b3.Position = b3.Position + Vector3.new(0,0.15,0)
                    b4.Position = b4.Position + Vector3.new(0,0.15,0)
                    b5.Position = b5.Position + Vector3.new(0,0.15,0)
                until not pressed
            end
        end
    end
end)

UIS.InputEnded:Connect(function(input, upKey)
    if not upKey then
        if input.KeyCode == Enum.KeyCode.R then
            pressed = false
        end
    end
end)

UIS.InputBegan:Connect(function(input, downKey)
    if not downKey then
        if input.KeyCode == Enum.KeyCode.F then
            if not pressed then
                pressed = true
                repeat wait()
                    lFork.Position = lFork.Position + Vector3.new(0,-0.15,0)
                    rFork.Position = rFork.Position + Vector3.new(0,-0.15,0)
                    b1.Position = b1.Position + Vector3.new(0,-0.15,0)
                    b2.Position = b2.Position + Vector3.new(0,-0.15,0)
                    b3.Position = b3.Position + Vector3.new(0,-0.15,0)
                    b4.Position = b4.Position + Vector3.new(0,-0.15,0)
                    b5.Position = b5.Position + Vector3.new(0,-0.15,0)
                until not pressed
            end
        end
    end
end)

UIS.InputEnded:Connect(function(input, downKey)
    if not downKey then
        if input.KeyCode == Enum.KeyCode.F then
            pressed = false
        end
    end
end)

UIS.InputBegan:Connect(function(input,gme)
    if input.KeyCode == Enum.KeyCode.V then
        vKeyPressed = true
        lFork.Position = lStart
        rFork.Position = rStart
        b1.Position = b1Start
        b2.Position = b2Start
        b3.Position = b3Start
        b4.Position = b4Start
        b5.Position = b5Start
        print("Forks were reset!")
    end
end)

UIS.InputBegan:Connect(function(input,gme)
    if input.KeyCode == Enum.KeyCode.G then
        gKeyPressed = true
        --[[This is where I want the player to press G and it will attach the forks to the pallet so they move together]]
    end
end)

1 answer

Log in to vote
0
Answered by 3 years ago

You can use a Welder plugin, I use Weld Plugin by Ozzypig It's much easier to use a plugin than write it manually...

0
Not what my goal is. The goal is when the player presses a key, it will check to see if they are under the pallet and weld the pallet and forks together so they both move... ryan97rut 5 — 3y
Ad

Answer this question