I have a LocalScript in which when a sound loops, it calls a RemoteEvent. (The part that calls the RemoteEvent is towards the bottom.) Here's that code:
repeat wait() until game.Players.LocalPlayer:FindFirstChild("PlayerGui")
game.Players.LocalPlayer.PlayerGui:SetTopbarTransparency(0)
local repStorage = game:GetService("ReplicatedStorage")
local remote = repStorage:WaitForChild("Remote")
local background = script.Parent.background
local play = script.Parent.play
local picture = script.Parent.picture
local name = script.Parent.name
local me = script.Parent.me
local shop = script.Parent.ShopButton
local count = 0
play.MouseButton1Click:Connect(function()
play:TweenPosition(UDim2.new(.375,0,1,0), "In", "Quad", 2)
wait(1)
name:TweenPosition(UDim2.new(1,0,.65,0), "In", "Quad", 2)
wait(1)
picture:TweenPosition(UDim2.new(0,0,-.6,0), "In", "Quad", 2)
wait(1.5)
repeat
background.BackgroundTransparency = background.BackgroundTransparency + 0.01
count = count + 1
wait(0.03)
until count == 100
background:TweenPosition(UDim2.new(1,0,1,0), "In", "Quad", .5)
wait(0.5)
local sound = Instance.new("Sound", game.Players.LocalPlayer) --Creates new sound in player
sound.Name = "oyy"
sound.SoundId = "rbxassetid://2778989543"
sound.Looped= true
sound:Play() --Plays sound
sound.DidLoop:Connect(function() --Checks if sound loops
remote:FireServer() --If it does, execute this
end)
end)
That part works fine I believe. Then, when the RemoteEvent is called it executes this code on the server:
local repStorage = game:GetService("ReplicatedStorage")
local remote = repStorage:WaitForChild("Remote")
remote.OnServerEvent:Connect(function(player) --When RemoteEvent is called, execute this
local yeahs = player:WaitForChild("leaderstats"):WaitForChild("yeahs") --Get player's stat
yeahs.Value = yeahs.Value + 1 --Adds one to player's stat
end)
The problem is that it seems the RemoteEvent is sometimes called multiple times or doesn't get called at all because when I test this in game, it will usually add 2-3 yeahs to player and sometimes it doesn't do anything at all. Does anybody know what is happening or how to fix it?

2 comments
I dont think using soundlooped is a good idea
It's literally the only way that I know of to do what I want unless there's another way of tracking when a sound loops.