audioparts = workspace.AudioParts local clonemusicEvent = game:GetService("ReplicatedStorage"):WaitForChild("HubTownMusic") locations = {} while true do wait() --print('waiting for player..') for i, v in pairs(game.Players:GetChildren()) do if v.Character ~= nil then print('found character') if v.Character:FindFirstChild("UpperTorso") ~= nil then repeat wait(.1) until (Vector3.new(audioparts.HubTownArea.Position) - v.Character.HumanoidRootPart.Position).magnitude <= 750 clonemusicEvent:FireClient(v) end --print('fired client') end end end
Creating an audio system that will detect if the player has the Audio GUI or not. Here is also the local script for context.
repeat wait() until game.Players.LocalPlayer.Character ~= nil local Players = game:GetService("Players") local Gui = game.Workspace.AudioParts.HubTownArea.Audio local cloneguievent = game:GetService("ReplicatedStorage"):WaitForChild("HubTownMusic") local Event = game.ReplicatedStorage.HubTownMusic Event.OnClientEvent:connect(function() wait() if game.Players.LocalPlayer.PlayerGui:FindFirstChild("Audio") then --print("Has gui") else --print("No gui") local Clone = Gui:Clone() Clone.Parent = game.Players.LocalPlayer.PlayerGui end end)
I understand that the loop spams the event and in that case can't work properly (or at all), so i'm asking for an alternative for the 'while true do' loop. Maybe Renderstepped would work? But how would I implement that efficiently? Anyone got any ideas or easy solutions (or complicated if need be.)
EDIT: The picture and the event being fired do not match up, but that is because there are multiple versions of the script with the only difference being a different GUI and event name. All versions still get exhausted and do not work.