mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-15 21:51:55 +00:00
UDP flashlight working and fix some type errors
This commit is contained in:
@@ -5,9 +5,22 @@
|
||||
local Flashlight = {}
|
||||
Flashlight.__index = Flashlight
|
||||
|
||||
type UDP = UnreliableRemoteEvent
|
||||
type FlashlightUDP = RBXScriptConnection
|
||||
type LocalPlayer = Player
|
||||
type HumanoidRootPart = BasePart
|
||||
|
||||
Flashlight.Enabled = false
|
||||
|
||||
function Flashlight.constructor(HumanoidRootPart: BasePart)
|
||||
local CharacterShared = _G.include(script, "CharacterShared")
|
||||
|
||||
local Flashlight_UDP = Instance.new("UnreliableRemoteEvent") :: UDP
|
||||
Flashlight_UDP.Name = "Flashlight"
|
||||
Flashlight_UDP.Parent = CharacterShared
|
||||
|
||||
local FlashlightUDP_Event: FlashlightUDP?
|
||||
|
||||
function Flashlight.constructor(LocalPlayer: LocalPlayer, HumanoidRootPart: HumanoidRootPart)
|
||||
local FlashlightPart = Instance.new("Part") :: Part
|
||||
FlashlightPart.Size = Vector3.new(.1,.1,.1)
|
||||
FlashlightPart.CFrame = HumanoidRootPart.CFrame
|
||||
@@ -18,21 +31,30 @@ function Flashlight.constructor(HumanoidRootPart: BasePart)
|
||||
|
||||
local SpotLight = Instance.new("SpotLight") :: SpotLight
|
||||
SpotLight.Color = Color3.new(1,1,1)
|
||||
SpotLight.Angle = 90
|
||||
SpotLight.Angle = 80
|
||||
SpotLight.Range = 30
|
||||
SpotLight.Brightness = 1
|
||||
SpotLight.Brightness = 2
|
||||
SpotLight.Shadows = true
|
||||
SpotLight.Enabled = false
|
||||
SpotLight.Parent = FlashlightPart
|
||||
|
||||
FlashlightPart.Anchored = false
|
||||
FlashlightPart.Parent = HumanoidRootPart
|
||||
|
||||
local ToggleSound = Instance.new("Sound") :: Sound
|
||||
ToggleSound.Name = "Flashlight"
|
||||
ToggleSound.SoundId = "rbxassetid://16454678462"
|
||||
ToggleSound.Volume = .5
|
||||
ToggleSound.Parent = HumanoidRootPart
|
||||
|
||||
if FlashlightUDP_Event then
|
||||
warn("[Server Flashlight]: UDP event was already created, duplicating...", debug.traceback())
|
||||
end
|
||||
FlashlightUDP_Event = Flashlight_UDP.OnServerEvent:Connect(function(Messenger: Player, CameraCFrame: CFrame)
|
||||
if Messenger.UserId == LocalPlayer.UserId then
|
||||
FlashlightPart.CFrame = CameraCFrame
|
||||
end
|
||||
end)
|
||||
|
||||
return setmetatable({
|
||||
FlashlightPart = FlashlightPart,
|
||||
SpotLight = SpotLight,
|
||||
@@ -40,10 +62,9 @@ function Flashlight.constructor(HumanoidRootPart: BasePart)
|
||||
}, Flashlight)
|
||||
end
|
||||
|
||||
function Flashlight:On(CameraCFrame: CFrame)
|
||||
function Flashlight:On()
|
||||
Flashlight.Enabled = true
|
||||
|
||||
(self.FlashlightPart :: Part).CFrame *= CameraCFrame;
|
||||
(self.ToggleSound :: Sound):Play();
|
||||
(self.SpotLight :: SpotLight).Enabled = Flashlight.Enabled
|
||||
end
|
||||
@@ -55,11 +76,11 @@ function Flashlight:Off()
|
||||
(self.SpotLight :: SpotLight).Enabled = Flashlight.Enabled
|
||||
end
|
||||
|
||||
function Flashlight:Toggle(CameraCFrame: CFrame?)
|
||||
function Flashlight:Toggle()
|
||||
if Flashlight.Enabled then
|
||||
self:Off()
|
||||
else
|
||||
self:On(CameraCFrame :: CFrame)
|
||||
self:On()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user