I’m making a game where you need to build a spaceship, and obviously there is a building mechanic and it works perfect.
Now I have a module and this script inside of the driver seat, what i want the server script to do is search through the engine part of the table on the module script and determine if there is a engine located on the ship, although instead of going through the whole table all it does is stop at the first type of engine and doesn’t go through the rest in the table.
Module:
local repStorage = game:GetService("ReplicatedStorage")
local buildingFolder = repStorage:WaitForChild("Build")
local buildingItems = buildingFolder.BuildingItems
local SeatFolder = buildingItems:WaitForChild("Seats")
local EngineFolder = buildingItems:WaitForChild("Engines")
local OtherFolder = buildingItems:WaitForChild("Other")
local items = {
["engines"] = {
["basic_engine"] = {
price = 50,
power = 70,
part = EngineFolder:FindFirstChild("BasicEngine"),
name = "BasicEngine"
},
["advanced_engine"] = {
price = 100,
power = 120,
part = EngineFolder:FindFirstChild("AdvancedEngine"),
name = "BasicEngine"
},
["jet_engine"] = {
price = 350,
power = 180,
part = EngineFolder:FindFirstChild("JetEngine"),
name = "BasicEngine"
},
["rocket_engine"] = {
price = 800,
power = 250,
part = EngineFolder:FindFirstChild("RocketEngine"),
name = "BasicEngine"
}
},
["seats"] = {
["basic_seat"] = {
price = 15,
part = SeatFolder:FindFirstChild("BasicSeat"),
name = "BasicSeat"
},
["basic_driver_seat"] = {
price = 30,
part = SeatFolder:FindFirstChild("BasicDriverSeat"),
name = "BasicDriverSeat"
}
},
["other"] = {
}
}
return items
Code that isn’t working inside of the ServerScriot inside a VehicleSeat:
script.Parent.Changed:Connect(function()
if script.Parent.Occupant then
script.LinearVelocity.Enabled = true
for _, engine in pairs(engines) do
print(engine.name)
local a = script.Parent.Parent:FindFirstChild(engine.name)
if a then
local engine = script.Parent.Parent:FindFirstChild(engine.name)
local seat = script.Parent
local front_speed = engine.power
local up_speed = 1
local max_height = 300
print("YEAH!")
while true do
wait(.5)
script.AngularVelocity.AngularVelocity = Vector3.new(0, -1 * seat.Steer, 0)
if seat.Throttle == 1 then
script.LinearVelocity.VectorVelocity = Vector3.new(0,up_speed,-front_speed)
end
if seat.Throttle == -1 then
script.LinearVelocity.VectorVelocity = Vector3.new(0,-up_speed,front_speed)
end
if seat.Throttle == 0 then
script.LinearVelocity.VectorVelocity = Vector3.new(0,0,0)
end
--if math.random(seat.Position.Y - seat.Position.Y / 2) == 0 then
-- script.LinearVelocity.VectorVelocity = Vector3.new(0,0,0)
--end
--if seat.Position.Y + seat.Size.Y / 2 > max_height then
-- script.LinearVelocity.VectorVelocity = Vector3.new(0,-up_speed,-front_speed)
--end
end
return
end
end
else
script.LinearVelocity.Enabled = false
end
end)
and a screenshot of the explorer: