Actor support

This commit is contained in:
2024-02-21 13:23:23 -05:00
parent ff16d8ceb3
commit e5f1a546b1
21 changed files with 284 additions and 73 deletions

View File

@@ -0,0 +1,68 @@
local Flashlight = {}
Flashlight.__index = Flashlight
local Remote = Instance.new("RemoteEvent") :: RemoteEvent
Remote.Name = "Flashlight"
Remote.Parent = _G.include(script, "CharacterShared")
function Flashlight.constructor(Head: BasePart)
local FlashlightPart = Instance.new("Part") :: Part
FlashlightPart.Size = Vector3.new(.1,.1,.1)
FlashlightPart.CFrame = Head.CFrame+Vector3.yAxis
FlashlightPart.CanCollide = false
FlashlightPart.CastShadow = false
FlashlightPart.Transparency = 1
local SpotLight = Instance.new("SpotLight") :: SpotLight
SpotLight.Color = Color3.new(1,1,1)
SpotLight.Angle = 80
SpotLight.Range = 30
SpotLight.Brightness = 1
SpotLight.Shadows = true
SpotLight.Enabled = false
SpotLight.Parent = FlashlightPart
local Weld = Instance.new("WeldConstraint") :: WeldConstraint
Weld.Part0 = Head
Weld.Part1 = FlashlightPart
Weld.Parent = FlashlightPart
FlashlightPart.Anchored = false
FlashlightPart.Parent = Head
local ToggleSound = Instance.new("Sound") :: Sound
ToggleSound.SoundId = "rbxassetid://16454678462"
ToggleSound.Volume = .5
ToggleSound.Parent = Head
return setmetatable({
SpotLight = SpotLight,
ToggleSound = ToggleSound,
Remote = Remote
}, Flashlight)
end
local FlashlightEnabled = false
function Flashlight:On()
FlashlightEnabled = true
self.ToggleSound:Play()
self.SpotLight.Enabled = FlashlightEnabled
end
function Flashlight:Off()
FlashlightEnabled = false
self.ToggleSound:Play()
self.SpotLight.Enabled = FlashlightEnabled
end
function Flashlight:Toggle()
-- FlashlightEnabled = not FlashlightEnabled
if FlashlightEnabled then
self:Off()
else
self:On()
end
end
return Flashlight