From ffca7ff16b722622c01c17d0c28fee373e520caf Mon Sep 17 00:00:00 2001 From: unittensor Date: Wed, 17 Apr 2024 23:16:57 -0400 Subject: [PATCH] Light switch animation --- src/server/main/Tags.lua | 4 ++-- src/server/main/init.server.lua | 29 +++++++++++++++++++++++------ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/server/main/Tags.lua b/src/server/main/Tags.lua index 00e9188..52958b5 100644 --- a/src/server/main/Tags.lua +++ b/src/server/main/Tags.lua @@ -61,8 +61,8 @@ export type LanternsTree = { } export type LightSwitchProperties = { - Switch: Instance?, - Lights: {Instance}?, + Switch: BasePart?, + Lights: {BasePart}?, Prompt: ProximityPrompt?, ClickSound: Sound?, ColorActivated: Color3?, diff --git a/src/server/main/init.server.lua b/src/server/main/init.server.lua index 1a89bd2..8174b60 100644 --- a/src/server/main/init.server.lua +++ b/src/server/main/init.server.lua @@ -30,6 +30,7 @@ StarterPlayer_Stuff() Lighting_Stuff() Workspace_Stuff() + --Map local Interactables = TagsConstructor:__Interactables() print("[DEBUG] Interactables=", Interactables) @@ -39,24 +40,40 @@ print("[DEBUG] Interactables=", Interactables) Guide for lights with toggable switches: TODO ]] +local TweenModule = require(Storage:WaitForChild("Tween")) +local LightSwitchTween = TweenModule.constructor(TweenInfo.new(.1, Enum.EasingStyle.Linear)) + for _, LightProperties in Interactables.LightSwitches do if LightProperties.Prompt and LightProperties.Switch then local Prompt = PromptsConstructor.constructor(LightProperties.Prompt, LightProperties.Switch) - local Enabled = false + local LightEnabled = false if LightProperties.ColorDeactivated and LightProperties.ColorActivated and LightProperties.Prompt and LightProperties.Lights then Prompt:AddHookTriggered(function(_Player: Player) - Enabled = not Enabled - --*Light switch animation* + LightEnabled = not LightEnabled + + local Switch = LightProperties.Switch + if Enabled then + LightSwitchTween:Start(Switch, { + CFrame = CFrame.new(Switch.Position)*CFrame.Angles(0,math.rad(90),0)+Vector3.new(0,.15,0) + }) + else + LightSwitchTween:Start(Switch, { + CFrame = CFrame.new(Switch.Position)*CFrame.Angles(0,math.rad(90),math.rad(70))-Vector3.new(0,.15,0) + }) + end + if LightProperties.ClickSound then LightProperties.ClickSound:Play() end for n: number = 1, #LightProperties.Lights do local LightObj = LightProperties.Lights[n] - LightObj.PointLight.Enabled = Enabled - - if Enabled then + local Light = LightObj:FindFirstChildWhichIsA("PointLight", true) or LightObj:FindFirstChildWhichIsA("SpotLight", true) + if Light then + Light.Enabled = LightEnabled + end + if LightEnabled then LightObj.Color = LightProperties.ColorActivated LightObj.Material = Enum.Material.Neon else