A while ago, a person told me instead of getting a gun to make a noise by just playing one audio, I can do Instance.new to make it sound more natural.
I can see where they’re going with this, but I’m not quite sure how to pull it off.
I am also having trouble parenting the Sound to the handle, and I have concerns if it’ll be laggy, and was wondering if there was a way to delete the sound after it’s added.
local Handle = script.Parent -- change as needed
function PlaySound(Id)
local Sound = Instance.new("Sound")
Sound.SoundId = Id
Sound.Parent = Handle
Sound:Play()
Sound.Ended:Wait()
Sound:Destroy()
end
Go to line 297 and remove an end. simply means end of file, as @MichaelEpicA stated. Rather than being the end of the script, you have typed out end, which is extra and errors the script.
local Handle = script.Parent -- your gun part
function PlaySound(Id)
local Sound = Instance.new("Sound")
Sound.SoundId = "rbxassetid://" .. Id
Sound.Parent = Handle
Sound:Play()
Sound.Ended:Connect(function()
Sound:Destroy()
end
end)
There’s no difference other than the concatenated string for the SoundId, which could be useful, but I don’t see a point in reposting an entire script for it.