Hey guys,
So am trying to make a part that plays a sound until a player is standing on it, and stops playing the sound when the player goes. The problem is that the sound doesn’t play.
Here’s the script (inside the part)
local part = script.Parent
local sound = script.Parent.Drumming
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
sound:Play()
else
print("not a player")
end
end)
part.TouchEnded:Connect(function()
sound:Stop()
end)
Thanks!
2 Likes
I suggest placing the sound instance inside of soundservice
local part = script.Parent
local sound = game:GetService("SoundService").Drumming
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
sound.Playing = true
sound:Play()
else
print("Not a player")
end
end)
part.TouchEnded:Connect(function()
sound.Playing = false
sound:Stop()
end)
Make sure your roblox volume is on.
1 Like
it is on.
will test and reply back.
Sound’s within the Sound Service may only be played by the client.
its a-okay for me if the sounds are played on the client, doesnt matter much.
You’ve misunderstood what I’m saying, the client & the client only can play sounds within the sound service via a Localscript. The solution to this issue is quite simple, move the sounds out of Sound Service and place them into workspace.
oop. u may be right, the code that mysterious gave didnt work. the sound was perviously inside the part, ill revert back and reply.
Ahh, alright. Turns out the TouchEnded event fires multiple times, even while standing on the part. This prevents the sound from ever really being played, a solution would be to have a loop running that would use :GetTouchingParts and determine if a player is still really touching.
1 Like
didnt work. tried chaning it to local also, moved the sound around to no avail. i think prob the touched events arent firing?
oops didnt read. will try and reply back.
Localscripts only run when a descendant of a player or character, and in this scenario, you wouldn’t want to put it in a Localscript.
1 Like
interestingly didnt work. heres what am doing in a serverscript inside the part:
while true do
wait()
local parts = script.Parent:GetTouchingParts()
for _, touchingpart in ipairs(parts) do
if touchingpart.Parent:FindFirstChild("Humanoid") then
script.Parent.Drumming:Play()
end
end
end
didnt code the part to stop the sound yet. also, when i was doing this the first time i forgot to add the wait()
resulting in the script timing out. is it related?
Shouldn’t matter too much, at least in this case.
ight ight. so ill prob change the sound’s property which controls the amount of distance the camera needs to be to hear the sound, forgot the name tho.
id probably also try out just playing the sound when the player touches, just to see if it even works.
worked. thanks for help @IceAlexander hope u have a good day ahead