Sorry if this is in the wrong topic.
-
Basically, I want to optimize my scripts as much as I can.
-
I don’t see a way to optimize my scripts any further.
Images of Locations, and more
Locations
Scripts
Script in "FinalPart"
local this_buttonGotHit = false local CompRoom = false local RoomFolder = script.Parent.Parent -- Choose where the current room folder should be. local door = RoomFolder.Door -- Choose local registeredPart = false if registeredPart == false then registeredPart = true wait(0.1) RoomFolder:SetAttribute("RequiredButtons",RoomFolder:GetAttribute("RequiredButtons") + 1) end local function TweenDoor() local duration = 1 local style = 2 local direction = 1 local ts = game:GetService("TweenService") local tween1 = TweenInfo.new(duration,style,direction) local properties1 = { Position = Vector3.new(door.Position.X,10,door.Position.Z), Size = Vector3.new(11,0.05,1.75) } local create1 = ts:Create(door,tween1,properties1) create1:Play() end local function CheckToTween() if RoomFolder:GetAttribute("ButtonsHit") >= RoomFolder:GetAttribute("RequiredButtons") and CompRoom == false then CompRoom = true wait(0.1) TweenDoor() end end script.Parent.Touched:Connect(function(hit) if game.Players:GetPlayerFromCharacter(hit.Parent) then if this_buttonGotHit == false then if RoomFolder:GetAttribute("ButtonsHit") == RoomFolder:GetAttribute("RequiredButtons") - 1 then this_buttonGotHit = true wait(0.1) script.Sound:Play() script.Parent.BrickColor = BrickColor.Red() if RoomFolder:GetAttribute("ButtonsHit") < RoomFolder:GetAttribute("RequiredButtons") then RoomFolder:SetAttribute("ButtonsHit",RoomFolder:GetAttribute("ButtonsHit") + 1) CheckToTween() end end end end end)
Script in every "Part"
local this_buttonGotHit = false local CompRoom = false local RoomFolder = script.Parent.Parent -- Choose where the current room folder should be. local door = RoomFolder.Door -- Choose local registeredPart = false if registeredPart == false then registeredPart = true wait(0.1) RoomFolder:SetAttribute("RequiredButtons",RoomFolder:GetAttribute("RequiredButtons") + 1) end local function TweenDoor() local duration = 1 local style = 2 local direction = 1 local ts = game:GetService("TweenService") local tween1 = TweenInfo.new(duration,style,direction) local properties1 = { Position = Vector3.new(door.Position.X,10,door.Position.Z), Size = Vector3.new(11,0.05,1.75) } local create1 = ts:Create(door,tween1,properties1) create1:Play() end script.Parent.Touched:Connect(function(hit) if game.Players:GetPlayerFromCharacter(hit.Parent) then if RoomFolder:GetAttribute("ButtonsHit") >= RoomFolder:GetAttribute("RequiredButtons") and CompRoom == false then CompRoom = true wait(0.1) TweenDoor() end if this_buttonGotHit == false then this_buttonGotHit = true wait(0.1) script.Sound:Play() script.Parent.BrickColor = BrickColor.Red() if RoomFolder:GetAttribute("ButtonsHit") < RoomFolder:GetAttribute("RequiredButtons") then RoomFolder:SetAttribute("ButtonsHit",RoomFolder:GetAttribute("ButtonsHit") + 1) end end end end)
Script in "Room1"
local RoomFolder = script.Parent local FinalButton = RoomFolder.FinalPart RoomFolder:GetAttributeChangedSignal("ButtonsHit"):Connect(function() if RoomFolder:GetAttribute("ButtonsHit") == RoomFolder:GetAttribute("RequiredButtons") - 1 then FinalButton.Color = Color3.fromRGB(0,255,0) end end)
Model if your confused:
Kit - RobloxThank you for putting the time into reading this and helping out!