local function soundhit(part, exactpos)
local att = Instance.new("Attachment")
att.WorldPosition = exactpos
att.Parent = part
att.Name = "SoundHit"
local material = part.Material.Name
if hitfolder:FindFirstChild(material) then
local soundc = hitfolder:FindFirstChild(material):FindFirstChild("Sound1"):Clone()
soundc.Parent = att
soundc.Name = "Hit"
soundc:Play()
end
end
Doesn’t seem to play , I already checked volumes and I checked immediately when the script runs. It’s a server script for a gun system, the sounds are not moderated. It only clones the sound.
2 Likes
What is hitfolder? Are you calling the function somewhere? can you add a Print(“Hello”) inside the soundhit function to see if it is working properly?
1 Like
hitfolder Is a folder inside the handle.

Everything works except the :Play()
1 Like
Still no, doesn’t play them.

Try putting a print()
statement to make sure your code is running.
what is part.Material.Name?
isnt its supposted to be tostring(part.Material)
oh also try to change sound it might be the sound issue.
After it prints “Played” can you see in-game the sound in the attachment? Can you call the soundhit function outside of it’s parent function? What Pumpky said. Are you allowed to use that sound?
It’s my sound that I created, yes you can see the sound and what do you mean “can you call the soundhit function outside of it’s parent function”?
part.Material.Name seems to work just fine
I created the sound and it is not moderated.
Can you get local function soundhit(part, exactpos)
function soundhit(part, exactpos)
by moving that function out of what function it is in?
Why is it local?
try
local soundc = hitfolder:FindFirstChild(material):FindFirstChild("Sound1"):Clone()
soundc.Parent = att
soundc.Name = "Hit"
soundc.PlayOnRemove = true
game.Debris:AddItem(soundc,0.01)
For all my functions I used local function in my script and it worked, even without local function it doesn’t work.
It deletes but doesn’t play. Weird thing it doesn’t play when cloned, if I preview it , I can hear it.
check console, audio discovery and look if theres a error.
if all dont work try to test your code in roblox client and not roblox studio.
No audio errors at all, and it doesn’t play in game either.
try to waitforchild, change the sound to some roblox audio or idk.