Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago

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

Log in to vote
1
Answered by
cabbler 1942 Moderation Voter
7 years ago

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

0
Thank you! It works now. Sans_Dreams 5 — 7y
Ad

Answer this question