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

What have I done wrong in my vehicle spawner script?

Hi guys, I've been trying to get this code to work for 2 days now. This is what it's supposed to do:

  1. When the left mouse button is clicked, and the tool is equipped, identify vehicle pad
  2. Clone the bike in ReplicatedStorage(no, it's not a possibility that these parts fell off the map. I anchored all of them.)
  3. Place the new bike on the pad
  4. Unanchor the bike
  5. Destroy itself.

Here's the code block: (yes, this is in a localscript.)

local ADFBike = game.ReplicatedStorage["ADF Bike"]
local Tool = script.Parent

function unanchor (m)
	for _,i in pairs (m:GetChildren()) do
		if i:IsA("BasePart") then
			i:MakeJoints()
			i.Anchored = false
		else
			unanchor(i)
		end
	end
end

Tool.Equipped:connect(function (Mouse)
	Mouse.Button1Up:connect(function ()
		print("Activated")
		local MTar = Mouse.Target
		if MTar.Name == "Vehicle Pad" then
			print("Determined")
			local NewBike = ADFBike:Clone()
			print("Cloned")
			NewBike.Parent = game.Workspace
			print("Parented")
			NewBike:MoveTo(Mouse.Target.Position + Vector3.new(0, 5, 0))
			print("Positioned")
			unanchor(NewBike)
			print("Unanchored")
			script.Parent:Destroy()
		end
	end)
end)

1 comment

1

Which of those print statements is running?

1 answer

✓ Accepted answer

local ADFBike = game.ReplicatedStorage["ADF Bike"]
local Tool = script.Parent

function unanchor (m)
    for _,i in pairs (m:GetChildren()) do
        if i:IsA("BasePart") then
            i:MakeJoints()
            i.Anchored = false
        else
            unanchor(i)
        end
    end
end

Tool.Equipped:connect(function (Mouse)
    Mouse.Button1Up:connect(function ()
        print("Activated")
        local MTar = Mouse.Target
        if MTar.Name == "Vehicle Pad" then
            print("Determined")
            local NewBike = ADFBike:Clone()
NewBike:MakeJoints()
            print("Cloned")
            NewBike.Parent = game.Workspace
            print("Parented")
            NewBike:MoveTo(Mouse.Target.Position + Vector3.new(0, 5, 0))
            print("Positioned")
            unanchor(NewBike)
            print("Unanchored")
NewBike:MakeJoints()
            script.Parent:Destroy()
        end
    end)
end)

1 comment

1

will add more later

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