@@ -8,6 +8,7 @@ local CollectionService = game:GetService("CollectionService")
88local TweenService = game :GetService (" TweenService" )
99local RunService = game :GetService (" RunService" )
1010local ProximityPromptService = game :GetService (" ProximityPromptService" )
11+ local VRService = game :GetService (" VRService" )
1112
1213local Players = game :GetService (" Players" )
1314local Config = require (Common .Config )
@@ -24,6 +25,8 @@ local OrbListenOnRemoteEvent = Common.Remotes.OrbListenOn
2425local OrbListenOffRemoteEvent = Common .Remotes .OrbListenOff
2526local OrbcamOnRemoteEvent = Common .Remotes .OrbcamOn
2627local OrbcamOffRemoteEvent = Common .Remotes .OrbcamOff
28+ local VRSpeakerChalkEquipRemoteEvent = Common .Remotes .VRSpeakerChalkEquip
29+ local VRSpeakerChalkUnequipRemoteEvent = Common .Remotes .VRSpeakerChalkUnequip
2730
2831local localPlayer
2932
@@ -195,9 +198,10 @@ function Gui.Init()
195198
196199 -- Do not allow Shift-C to turn _off_ orbcam that was turned on
197200 -- via the topbar button
198- if Gui .Orbcam and not Gui .OrbcamGuiOff then
199- return
200- end
201+ if Gui .Orbcam and not Gui .OrbcamGuiOff then return end
202+
203+ -- Do not allow the shortcut when not attached
204+ if Gui .Orb == nil then return end
201205
202206 if Gui .OrbcamIcon :getToggleState () == " selected" then
203207 Gui .OrbcamIcon :deselect ()
@@ -223,11 +227,67 @@ function Gui.Init()
223227 OrbTweeningStartRemoteEvent .OnClientEvent :Connect (Gui .OrbTweeningStart )
224228 OrbTweeningStopRemoteEvent .OnClientEvent :Connect (Gui .OrbTweeningStop )
225229
230+ -- In VR we need to tell other clients when we equip the chalk
231+ if VRService .VREnabled then
232+ local chalkTool = localPlayer .Backpack :WaitForChild (" MetaChalk" , 20 )
233+ if chalkTool ~= nil then
234+ chalkTool .Equipped :Connect (function ()
235+ VRSpeakerChalkEquipRemoteEvent :FireServer ()
236+ end )
237+ chalkTool .Unequipped :Connect (function ()
238+ VRSpeakerChalkUnequipRemoteEvent :FireServer ()
239+ end )
240+ else
241+ print (" [MetaOrb] Failed to find MetaChalk tool" )
242+ end
243+ end
244+
245+ Gui .HandleVR ()
226246 Gui .CreateTopbarItems ()
227247
228248 print (" [Orb] Gui Initialised" )
229249end
230250
251+ function Gui .MakePlayerTransparent (plr , transparency )
252+ if plr == nil then
253+ print (" [MetaOrb] Passed nil player to MakePlayerTransparent" )
254+ return
255+ end
256+
257+ if plr .Character == nil then return end
258+
259+ local character = plr .Character
260+
261+ for _ , desc in ipairs (character :GetDescendants ()) do
262+ if desc :IsA (" BasePart" ) then
263+ desc .Transparency = 1 - (transparency * (1 - desc .Transparency ))
264+ desc .CastShadow = false
265+ end
266+ end
267+
268+ -- origTransparency = 1 - 1/0.2 * (1 - newTransparency)
269+ end
270+
271+ function Gui .HandleVR ()
272+ VRSpeakerChalkEquipRemoteEvent .OnClientEvent :Connect (function (speaker )
273+ if Gui .Orb == nil then return end
274+ if Gui .Orb .Speaker .Value == nil then return end
275+ if Gui .Orb .Speaker .Value ~= speaker then return end
276+
277+ if speaker == localPlayer then return end
278+ Gui .MakePlayerTransparent (speaker , 0.2 )
279+ end )
280+
281+ VRSpeakerChalkUnequipRemoteEvent .OnClientEvent :Connect (function (speaker )
282+ if Gui .Orb == nil then return end
283+ if Gui .Orb .Speaker .Value == nil then return end
284+ if Gui .Orb .Speaker .Value ~= speaker then return end
285+
286+ if speaker == localPlayer then return end
287+ Gui .MakePlayerTransparent (speaker , 1 / 0.2 )
288+ end )
289+ end
290+
231291-- We create a part inside the player's head, whose CFrame
232292-- is tracked by SetListener
233293function Gui .InitEar ()
@@ -430,12 +490,32 @@ function Gui.AttachSpeaker(orb)
430490
431491 -- This event fires when the running speed changes
432492 local humanoid = localPlayer .Character :WaitForChild (" Humanoid" )
433- Gui .RunningConnection = humanoid .Running :Connect (function (speed )
434- if speed == 0 then
435- -- They were moving and then stood still
436- OrbSpeakerMovedRemoteEvent :FireServer (Gui .Orb )
437- end
438- end )
493+ if VRService .VREnabled then
494+ local counter = 0
495+ local timeTillPositionCheck = 2
496+ local playerPosAtLastCheck = localPlayer .Character .PrimaryPart .Position
497+
498+ Gui .RunningConnection = RunService .Heartbeat :Connect (function (step )
499+ counter = counter + step
500+ if counter >= timeTillPositionCheck then
501+ counter -= timeTillPositionCheck
502+
503+ if localPlayer .Character ~= nil and localPlayer .Character .PrimaryPart ~= nil then
504+ if (localPlayer .Character .PrimaryPart .Position - playerPosAtLastCheck ).Magnitude > 2 then
505+ OrbSpeakerMovedRemoteEvent :FireServer (Gui .Orb )
506+ end
507+ playerPosAtLastCheck = localPlayer .Character .PrimaryPart .Position
508+ end
509+ end
510+ end )
511+ else
512+ Gui .RunningConnection = humanoid .Running :Connect (function (speed )
513+ if speed == 0 then
514+ -- They were moving and then stood still
515+ OrbSpeakerMovedRemoteEvent :FireServer (Gui .Orb )
516+ end
517+ end )
518+ end
439519end
440520
441521function Gui .CreateTopbarItems ()
0 commit comments