| |
|
| |
|
| | local CollectionService = game:GetService("CollectionService")
|
| | local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
| | local RunService = game:GetService("RunService")
|
| |
|
| | local ExplorationConfig = require(ReplicatedStorage:WaitForChild("Shared"):WaitForChild("ExplorationConfig"))
|
| |
|
| |
|
| | local function bindWeightSwitch(switchModel)
|
| | local platePart = switchModel:FindFirstChild("Plate")
|
| | local targetDoor = switchModel:FindFirstChild("LinkedDoor") or switchModel.Parent:FindFirstChild("Door")
|
| |
|
| | if not platePart or not targetDoor then return end
|
| |
|
| | local config = ExplorationConfig.Puzzles.WeightSwitch
|
| | local isActive = false
|
| |
|
| | RunService.Heartbeat:Connect(function()
|
| |
|
| | local touchingParts = workspace:GetPartsInPart(platePart)
|
| | local totalMass = 0
|
| |
|
| | for _, part in ipairs(touchingParts) do
|
| | if part:IsA("BasePart") and not part.Anchored then
|
| | totalMass = totalMass + part.AssemblyMass
|
| | end
|
| | end
|
| |
|
| | if totalMass >= config.RequiredWeight and not isActive then
|
| | isActive = true
|
| | platePart.BrickColor = BrickColor.new("Bright green")
|
| |
|
| | targetDoor.Transparency = 0.5
|
| | targetDoor.CanCollide = false
|
| | print("Puzzle Solved: Door Opened")
|
| |
|
| | elseif totalMass < config.RequiredWeight and isActive then
|
| | isActive = false
|
| | platePart.BrickColor = BrickColor.new("Bright red")
|
| |
|
| | targetDoor.Transparency = 0
|
| | targetDoor.CanCollide = true
|
| | print("Puzzle Reset: Door Closed")
|
| | end
|
| | end)
|
| | end
|
| |
|
| | CollectionService:GetInstanceAddedSignal("WeightSwitch"):Connect(bindWeightSwitch)
|
| | for _, switch in pairs(CollectionService:GetTagged("WeightSwitch")) do
|
| | bindWeightSwitch(switch)
|
| | end
|
| |
|
| |
|
| | local function bindSwampZone(zonePart)
|
| | local config = ExplorationConfig.Biomes.Swamp
|
| |
|
| | RunService.Heartbeat:Connect(function(dt)
|
| | local touchingParts = workspace:GetPartsInPart(zonePart)
|
| | for _, part in ipairs(touchingParts) do
|
| |
|
| | if part:IsA("BasePart") and not part.Anchored and not CollectionService:HasTag(part, "SwampTires") then
|
| |
|
| | part.AssemblyLinearVelocity = Vector3.new(
|
| | part.AssemblyLinearVelocity.X,
|
| | -config.SinkingSpeed,
|
| | part.AssemblyLinearVelocity.Z
|
| | )
|
| | end
|
| |
|
| |
|
| | end
|
| | end)
|
| | end
|
| |
|
| | CollectionService:GetInstanceAddedSignal("SwampZone"):Connect(bindSwampZone)
|
| | for _, zone in pairs(CollectionService:GetTagged("SwampZone")) do
|
| | bindSwampZone(zone)
|
| | end
|
| |
|