Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Value not increasing when sound loops?

I just need the player's value to increase by one when the sound loops but it isn't doing anything right now. It worked earlier but I changed it around and now nothing happens when the sound loops. This is in a script in ServerScriptService and here is the code:

local DataStore = game:GetService("DataStoreService")
local ds1 = DataStore:GetDataStore("ExampleDataStore")

game.Players.PlayerAdded:Connect(function(player)
	
	local leader = Instance.new("Folder", player)
	leader.Name = "leaderstats"
	
	local yeahs = Instance.new("IntValue", leader)
	yeahs.Name = "yeahs"
	yeahs.Value = ds1:GetAsync(player.UserId) or 0
	ds1:SetAsync(player.UserId, yeahs.Value)
	
	local sound = Instance.new("Sound", player)
	sound.Name = "oyy"
	sound.SoundId = "rbxassetid://2778989543"
	sound.Looped= true

	sound.DidLoop:Connect(function()
		yeahs.Value = yeahs.Value + 1
	end)
	
	while wait(60) do
		print("Saving Data")
		ds1:SetAsync(player.UserId, yeahs.Value)
		print(player.UserId.."'s Data of "..yeahs.Value.." "..yeahs.Name.." has been saved!")
	end
end)
	
game.Players.PlayerRemoving:connect(function(player)
	print("Saving Data")
	ds1:SetAsync(player.UserId, player.leaderstats.yeahs.Value)
	print(player.Name.."'s Data of "..player.leaderstats.yeahs.Value.." "..player.leaderstats.yeahs.Name.." has been saved!")
end)

Saving and loading the data works fine, it's just that the value doesn't change when the sound loops. Also, I know there is no sound:Play() in this script, that's because it is located in a LocalScript. Here's that code if you need to see it too (it's just an intro gui script that plays the sound when it's finished):

repeat wait() until game.Players.LocalPlayer:FindFirstChild("PlayerGui")

game.Players.LocalPlayer.PlayerGui:SetTopbarTransparency(0)

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)
	game.Players.LocalPlayer:WaitForChild("oyy"):Play() --this plays the sound that is made in the player in the server script
end)

1 answer

✓ Accepted answer

Use

yeahs.Value =
	yeahs.Value + 1

instead of

yeahs.Value = yeahs.Value + 1

Just try that, long time ago I had the same problem and that helped..

This discussion is preserved as it was. New answers, comments, and votes are closed.