| |
|
| |
|
| | local CollectionService = game:GetService("CollectionService")
|
| | local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
| |
|
| | local WireLogicConfig = require(ReplicatedStorage:WaitForChild("Shared"):WaitForChild("WireLogicConfig"))
|
| | local WireConnectEvent = ReplicatedStorage:WaitForChild("Events"):WaitForChild("WireConnectEvent")
|
| |
|
| |
|
| | local connections = {}
|
| | local componentStates = {}
|
| |
|
| |
|
| | local function updateState(part, newState)
|
| | if componentStates[part] == newState then return end
|
| | componentStates[part] = newState
|
| |
|
| |
|
| | if newState then
|
| | if part:IsA("BasePart") then
|
| |
|
| | part.Material = Enum.Material.Neon
|
| | end
|
| | else
|
| | if part:IsA("BasePart") then
|
| | part.Material = Enum.Material.SmoothPlastic
|
| | end
|
| | end
|
| |
|
| |
|
| | local compType = part:GetAttribute("ComponentType")
|
| | if compType == "Target" then
|
| | local targetFunc = part:GetAttribute("TargetFunction")
|
| | if targetFunc == "ToggleDoor" then
|
| |
|
| |
|
| | print("Door toggled to " .. tostring(newState))
|
| | elseif targetFunc == "ToggleConveyor" then
|
| |
|
| | local conveyorVelocity = part:GetAttribute("ConveyorSpeed") or 5
|
| | part.AssemblyLinearVelocity = newState and (part.CFrame.LookVector * conveyorVelocity) or Vector3.new()
|
| | end
|
| | end
|
| |
|
| |
|
| | local targets = connections[part]
|
| | if targets then
|
| | for _, targetPart in pairs(targets) do
|
| |
|
| | updateState(targetPart, newState)
|
| | end
|
| | end
|
| | end
|
| |
|
| |
|
| | local function bindSource(sourcePart)
|
| | local sourceType = sourcePart:GetAttribute("SourceType")
|
| |
|
| | if sourceType == "Button" then
|
| |
|
| | local prompt = sourcePart:FindFirstChild("ProximityPrompt")
|
| | if not prompt then
|
| | prompt = Instance.new("ProximityPrompt")
|
| | prompt.ActionText = "Press"
|
| | prompt.Parent = sourcePart
|
| | end
|
| |
|
| | prompt.Triggered:Connect(function(player)
|
| |
|
| | updateState(sourcePart, true)
|
| | task.delay(1, function()
|
| | updateState(sourcePart, false)
|
| | end)
|
| | end)
|
| |
|
| | elseif sourceType == "Lever" then
|
| | local prompt = sourcePart:FindFirstChild("ProximityPrompt")
|
| | if not prompt then
|
| | prompt = Instance.new("ProximityPrompt")
|
| | prompt.ActionText = "Toggle"
|
| | prompt.Parent = sourcePart
|
| | end
|
| |
|
| | prompt.Triggered:Connect(function(player)
|
| |
|
| | local currentState = componentStates[sourcePart] or false
|
| | updateState(sourcePart, not currentState)
|
| | end)
|
| | end
|
| | end
|
| |
|
| |
|
| | CollectionService:GetInstanceAddedSignal("LogicSource"):Connect(bindSource)
|
| | for _, src in pairs(CollectionService:GetTagged("LogicSource")) do
|
| | bindSource(src)
|
| | end
|
| |
|
| |
|
| | WireConnectEvent.OnServerEvent:Connect(function(player, sourcePart, targetPart)
|
| |
|
| | if not sourcePart or not targetPart then return end
|
| |
|
| |
|
| | if (sourcePart.Position - targetPart.Position).Magnitude > WireLogicConfig.MaxWireLength then
|
| | print("Wire too long!")
|
| | return
|
| | end
|
| |
|
| |
|
| | if not connections[sourcePart] then
|
| | connections[sourcePart] = {}
|
| | end
|
| |
|
| | table.insert(connections[sourcePart], targetPart)
|
| |
|
| |
|
| | local attachment0 = sourcePart:FindFirstChild("WireAtt") or Instance.new("Attachment", sourcePart)
|
| | attachment0.Name = "WireAtt"
|
| |
|
| | local attachment1 = targetPart:FindFirstChild("WireAtt") or Instance.new("Attachment", targetPart)
|
| | attachment1.Name = "WireAtt"
|
| |
|
| | local beam = Instance.new("Beam")
|
| | beam.Attachment0 = attachment0
|
| | beam.Attachment1 = attachment1
|
| | beam.FaceCamera = true
|
| | beam.Width0 = 0.1
|
| | beam.Width1 = 0.1
|
| | beam.Color = ColorSequence.new(Color3.new(0,0,0))
|
| | beam.Parent = sourcePart
|
| |
|
| | print("Wire connected from", sourcePart.Name, "to", targetPart.Name)
|
| | end)
|
| |
|