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

Can I make this pinsetter function the same way without writing this much code?

Asked by 3 years ago

local pinsetter = script.Parent.Parent.Pinsetter1 local sweeper = script.Parent.Parent.Sweep1 local pins = script.Parent.Parent.BowlingPins1 local ballreturn = script.Parent.Parent.BallReturn1 local BackupPins = pins:Clone() local DB = false local Running = true local Sweep_Y_Axis = Vector3.new(0,3.79,0) local Sweep_X_Axis = Vector3.new(10.98,0,0) local Setter_Y_Axis = Vector3.new(0,2.583,0) local sweeper_Main = sweeper.BasePart.Pos local pinsetter_Main = pinsetter.MainP.Pos local wobbling = {} local Cycle_Button = script.Parent.Parent.KeyPad1 local Screen = script.Parent.Parent.Lane1Monitor local Runnin1 = true local Lane_Lights = script.Parent.Parent.MaskingUnit.Cover.Lane1ThrowLight local Cycle_1_Light = Lane_Lights.BallLight1.Union local Cycle_2_Light = Lane_Lights.BallLight2.Union local Strike_Light = Lane_Lights.StrikeLight.Union

function Weld_Regen() pins:Destroy() pins = BackupPins:Clone() pins.Parent = game.Workspace pins:MakeJoints() pins.Name = "BowlingPins1" end

function Weld() for i,v in pairs(pins:GetChildren()) do local upvector = v.CFrame:vectorToWorldSpace( Vector3.new(0,1,0) ) local angle = math.acos(upvector:Dot(Vector3.new(0,1,0)))*180/math.pi if angle < 5 then local weld = Instance.new("Weld", v) weld.C0 = v.CFrame:inverse() * pinsetter.MainP.CFrame weld.Part0 = v weld.Part1 = pinsetter.MainP elseif angle < 45 then wobbling.Orientation = Vector3.new(0,0,0) table.insert(wobbling,v) local weld = Instance.new("Weld", v) weld.C0 = v.CFrame:inverse() * pinsetter.MainP.CFrame weld.Part0 = v weld.Part1 = pinsetter.MainP else end end end

function UnWeld() for i,v in pairs(pins:GetChildren()) do if v:FindFirstChild("Weld") ~= nil then v.Weld:Destroy()

end end end

local function IsPinDown(pinNumber) local pin = pins:FindFirstChild("Pin"..pinNumber) local rotX,rotZ = math.abs(pin.Rotation.X),math.abs(pin.Rotation.Z) if rotX > 30 or rotZ > 30 then return "IsDown" else return "NotDown" end end

local function StrikeDetection() Strike = true for i = 1,10 do local state = IsPinDown(i) if state == "NotDown" then Strike = false end end if Strike then return true end end

function Cycle1() sweeper_Main.Position = sweeper_Main.Position - Sweep_Y_Axis wait(2) sweeper_Main.Position = sweeper_Main.Position + Sweep_X_Axis wait(2) sweeper_Main.Position = sweeper_Main.Position - Sweep_X_Axis wait(2) wait(1) pinsetter_Main.Position = pinsetter_Main.Position - Setter_Y_Axis wait(2) Weld_Regen() wait(1) pinsetter_Main.Position = pinsetter_Main.Position + Setter_Y_Axis wait(2) sweeper_Main.Position = sweeper_Main.Position + Sweep_Y_Axis Runnin1 = true
end

function Cycle2() sweeper_Main.Position = sweeper_Main.Position - Sweep_Y_Axis wait(2) pinsetter_Main.Position = pinsetter_Main.Position - Setter_Y_Axis wait(2) Weld() wait(1) pinsetter_Main.Position = pinsetter_Main.Position + Setter_Y_Axis wait(2) sweeper_Main.Position = sweeper_Main.Position + Sweep_X_Axis wait(2) sweeper_Main.Position = sweeper_Main.Position - Sweep_X_Axis wait(2) pinsetter_Main.Position = pinsetter_Main.Position - Setter_Y_Axis wait(2) UnWeld() wait(1) pinsetter_Main.Position = pinsetter_Main.Position + Setter_Y_Axis wait(2) sweeper_Main.Position = sweeper_Main.Position + Sweep_Y_Axis Runnin1 = true
end

function Cycle() if Running == true then Running = false DB = true Screen.Main.SurfaceGui.ON.Current_Cycle_Status.Text = "First Ball" Cycle_1_Light.BrickColor = BrickColor.new("Really red") Cycle_2_Light.BrickColor = BrickColor.new("Really black") Strike_Light.BrickColor = BrickColor.new("Really black") Cycle1() wait(13) Running = true end end Cycle_Button.Main.SurfaceGui.Frame.Cycle.MouseButton1Click:Connect(Cycle)

function Main() if Runnin1 == true then if DB == true then Runnin1 = false wait(1) Cycle1() Cycle_1_Light.BrickColor = BrickColor.new("Really red") Cycle_2_Light.BrickColor = BrickColor.new("Really black") Strike_Light.BrickColor = BrickColor.new("Really black") Screen.Main.SurfaceGui.ON.Current_Cycle_Status.Text = "First Ball" DB = false elseif DB == false then Runnin1 = false wait(2) StrikeDetection() if Strike == true then Cycle1() Cycle_1_Light.BrickColor = BrickColor.new("Really red") Cycle_2_Light.BrickColor = BrickColor.new("Really black") Screen.Main.SurfaceGui.ON.Current_Cycle_Status.Text = "First Ball" DB = false elseif Strike == false then Cycle2() Cycle_1_Light.BrickColor = BrickColor.new("Really red") Cycle_2_Light.BrickColor = BrickColor.new("Really red") Strike_Light.BrickColor = BrickColor.new("Really black") Screen.Main.SurfaceGui.ON.Current_Cycle_Status.Text = "Second Ball" DB = true

end end end end

script.Parent.Touched:Connect(Main)

0
You didn't explain the code and it's hard to read since it's not on a code block. Xx_XSanderPlayXx 160 — 3y

Answer this question