generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: How to change a vehicle to a tool

Previous Thread :: Next Thread 
JonathanW123 is not online. JonathanW123
Joined: 04 Apr 2012
Total Posts: 5832
23 Nov 2013 11:20 AM
I have made a race car, but i wanna make it a tool, so if you click the tool(Part of backpack), you will instantly be in the driver's seat of the vehicle, just like Ro-Ped, Ro-torcycle, etc.

How would I script this?

Help would be really appreciated!
Report Abuse
JonathanW123 is not online. JonathanW123
Joined: 04 Apr 2012
Total Posts: 5832
23 Nov 2013 11:26 AM
bump
Report Abuse
JonathanW123 is not online. JonathanW123
Joined: 04 Apr 2012
Total Posts: 5832
23 Nov 2013 11:29 AM
b2
Report Abuse
JonathanW123 is not online. JonathanW123
Joined: 04 Apr 2012
Total Posts: 5832
23 Nov 2013 11:32 AM
b3
Report Abuse
JonathanW123 is not online. JonathanW123
Joined: 04 Apr 2012
Total Posts: 5832
23 Nov 2013 11:42 AM
b4
Report Abuse
JonathanW123 is not online. JonathanW123
Joined: 04 Apr 2012
Total Posts: 5832
23 Nov 2013 11:45 AM
b5
Report Abuse
Unsubstantial is not online. Unsubstantial
Joined: 11 Sep 2012
Total Posts: 872
23 Nov 2013 11:47 AM
local vehicle=game.ServerStorage.Vehicle
local tool=script.Parent --hopperbin also

tool.Selected:connect(function(mouse)

mouse.Button1Down:connect(function()
local clonedVehicle=vehicle:Clone()
clonedVehicle.Parent=workspace
clonedVehicle:MoveTo(game.Players.LocalPlayer.Character.Torso.Position)
game.Players.LocalPlayer.Character.Torso.CFrame=clonedVehicle.DriverSeat.CFrame+Vector3.new(0,3,0)
script:remove()
end)

end)

Please ensure that this is a hopperbin, and there's a Seat named "DriverSeat" inside of the vehicle.
Report Abuse
JonathanW123 is not online. JonathanW123
Joined: 04 Apr 2012
Total Posts: 5832
23 Nov 2013 11:51 AM
HopperBin? Explain what I require.
Report Abuse
Unsubstantial is not online. Unsubstantial
Joined: 11 Sep 2012
Total Posts: 872
23 Nov 2013 11:53 AM
In Studio, Basic Objects pane: Insert a HopperBin. Inside of that, put a regular script and paste the code into it.

Then you can use the Clone method to clone it to players' backpacks in a main script. Else if you want everyone to have it on entry, put it into the StarterPack.
Report Abuse
JonathanW123 is not online. JonathanW123
Joined: 04 Apr 2012
Total Posts: 5832
23 Nov 2013 11:57 AM
Do you wanna join.me and help me make this work?
Report Abuse
Unsubstantial is not online. Unsubstantial
Joined: 11 Sep 2012
Total Posts: 872
23 Nov 2013 12:03 PM
Define 'join'.
Seeing as this is a studio task, I really can't help you. You'd need to do it solo.
Report Abuse
JonathanW123 is not online. JonathanW123
Joined: 04 Apr 2012
Total Posts: 5832
23 Nov 2013 12:08 PM
No. It's a thing that lets you see my screen, and you can chat with me also. So you can see errors and all that
Report Abuse
chickenman158 is not online. chickenman158
Joined: 18 Jan 2011
Total Posts: 915
23 Nov 2013 12:09 PM
Skype is a better idea. Just saiyan.

Report Abuse
Unsubstantial is not online. Unsubstantial
Joined: 11 Sep 2012
Total Posts: 872
23 Nov 2013 12:15 PM
Unnecessary, just put a HopperBin in StarterPack, a script inside of that w/ the code.

As far as TeamV or Skype goes, no thanks.
Report Abuse
JonathanW123 is not online. JonathanW123
Joined: 04 Apr 2012
Total Posts: 5832
23 Nov 2013 12:19 PM
Well, it works, it's just when I spawn the vehicle, it falls apart.
Report Abuse
Unsubstantial is not online. Unsubstantial
Joined: 11 Sep 2012
Total Posts: 872
23 Nov 2013 12:25 PM
Alright, I'll get back to you in 30 mins. Going out momentarily.
Report Abuse
Unsubstantial is not online. Unsubstantial
Joined: 11 Sep 2012
Total Posts: 872
23 Nov 2013 02:14 PM
Ah, you're going to need to weld the vehicle together then.

local vehicle=game.ServerStorage.Vehicle
local tool=script.Parent --hopperbin also

tool.Selected:connect(function(mouse)

mouse.Button1Down:connect(function()
local clonedVehicle=vehicle:Clone()

for i,v in pairs(clonedVehicle) do
v.Anchored=true
end

function weld()
local parts,last = {}
local function scan(parent)
for _,v in pairs(parent:GetChildren()) do
if (v:IsA("BasePart")) then
if (last) then
local w = Instance.new("Weld")
w.Name = ("%s_Weld"):format(v.Name)
w.Part0,w.Part1 = last,v
w.C0 = last.CFrame:inverse()
w.C1 = v.CFrame:inverse()
w.Parent = last
end
last = v
table.insert(parts,v)
end
scan(v)
end
end
scan(clonedVehicle)
for _,v in pairs(parts) do
v.Anchored = false
end
end

weld()

clonedVehicle.Parent=workspace
clonedVehicle:MoveTo(game.Players.LocalPlayer.Character.Torso.Position)
game.Players.LocalPlayer.Character.Torso.CFrame=clonedVehicle.DriverSeat.CFrame+Vector3.new(0,3,0)
script:remove()
end)

end)
Report Abuse
JonathanW123 is not online. JonathanW123
Joined: 04 Apr 2012
Total Posts: 5832
23 Nov 2013 04:09 PM
It is welded but unanchored
Report Abuse
Unsubstantial is not online. Unsubstantial
Joined: 11 Sep 2012
Total Posts: 872
23 Nov 2013 09:00 PM
I'm confused now. I thought you wanted it to be unanchored so that it's drivable? Else, specify and I will help you.
Report Abuse
JonathanW123 is not online. JonathanW123
Joined: 04 Apr 2012
Total Posts: 5832
24 Nov 2013 08:55 AM
It IS unanchored, but welded. but when I spawn it, it falls apart.
Report Abuse
Unsubstantial is not online. Unsubstantial
Joined: 11 Sep 2012
Total Posts: 872
24 Nov 2013 02:20 PM
Then surely my last script should help? It'll stop it from falling apart.
Report Abuse
JonathanW123 is not online. JonathanW123
Joined: 04 Apr 2012
Total Posts: 5832
24 Nov 2013 03:21 PM
Lemme try it.
Report Abuse
JonathanW123 is not online. JonathanW123
Joined: 04 Apr 2012
Total Posts: 5832
24 Nov 2013 03:25 PM
Errors :
16:24:37.187 - Players.Player1.Backpack.Bloxxer.Script:9: bad argument #1 to 'pairs' (table expected, got userdata)
16:24:37.188 - Script 'Players.Player1.Backpack.Bloxxer.Script', Line 9
16:24:37.188 - stack end
16:24:37.189 - Disconnected event because of exception
Report Abuse
Unsubstantial is not online. Unsubstantial
Joined: 11 Sep 2012
Total Posts: 872
24 Nov 2013 04:42 PM
local vehicle=game.ServerStorage.Vehicle
local tool=script.Parent --hopperbin also

tool.Selected:connect(function(mouse)

mouse.Button1Down:connect(function()
local clonedVehicle=vehicle:Clone()

for i,v in pairs(clonedVehicle:GetChildren()) do
v.Anchored=true
end

function weld()
local parts,last = {}
local function scan(parent)
for _,v in pairs(parent:GetChildren()) do
if (v:IsA("BasePart")) then
if (last) then
local w = Instance.new("Weld")
w.Name = ("%s_Weld"):format(v.Name)
w.Part0,w.Part1 = last,v
w.C0 = last.CFrame:inverse()
w.C1 = v.CFrame:inverse()
w.Parent = last
end
last = v
table.insert(parts,v)
end
scan(v)
end
end
scan(clonedVehicle)
for _,v in pairs(parts) do
v.Anchored = false
end
end

weld()

clonedVehicle.Parent=workspace
clonedVehicle:MoveTo(game.Players.LocalPlayer.Character.Torso.Position)
game.Players.LocalPlayer.Character.Torso.CFrame=clonedVehicle.DriverSeat.CFrame+Vector3.new(0,3,0)
script:remove()
end)

end)
Report Abuse
JonathanW123 is not online. JonathanW123
Joined: 04 Apr 2012
Total Posts: 5832
24 Nov 2013 06:15 PM
19:14:49.607 - Anchored is not a valid member of Model
19:14:49.608 - Script 'Players.Player1.Backpack.Bloxxer.Script', Line 10
19:14:49.608 - stack end
19:14:49.608 - Disconnected event because of exception
19:15:12.716 - ToolTip is not a valid member of HopperBin
19:15:12.717 - Script 'CoreGui.RobloxGui.CurrentLoadout.CoreScripts/BackpackScript', Line 604
19:15:12.717 - stack end
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image