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

Audio-playing script doesn't work for ROBLOX Player, and only works for Studio. Why doesn't it work?

Pretty much, I'm making a roleplay, and I need audio for certain areas, yeah?

Here's the script:

local ID = 508851549

--script.Parent.Transparency = 1
game.Players.PlayerAdded:connect(function(plr)
	plr.CharacterAdded:connect(function(char)
		local canrend = true
		game:GetService("RunService").RenderStepped:connect(function()
			local part = char:WaitForChild("HumanoidRootPart")
			if (part.Position - script.Parent.Position).magnitude < script.Parent.Size.magnitude/3 and canrend then
				canrend = false
				local sound = Instance.new("Sound",plr.PlayerGui)
				sound.SoundId,sound.Looped = ("rbxassetid://"..ID),true sound:Play()
				repeat wait() until(part.Position - script.Parent.Position).magnitude > script.Parent.Size.magnitude/3
				canrend = true
				sound:Destroy()
			end
		end)
	end)
end)

It works fine in Studio, but when I launch the game and into the player, there is no sound. Any help?

1 answer

✓ Accepted answer

RenderStepped doesn't fire on the server, only clients. Heartbeat is the server equivalent.

1 comment

0

Thank you! It works now.

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