How do I add sound to a ProximityPrompt?

I’m making a Hood game right now, and so I need something for Criminals to rob:

I have this ATM right here, that How2Roblox put out there:

ATM

Here’s the Script:
game.Players.PlayerAdded:Connect(function(plr)

local ls = Instance.new("Folder")
ls.Name = "leaderstats"
ls.Parent = plr

local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Parent = ls

end)

local pps = game:GetService(“ProximityPromptService”)

pps.PromptTriggered:Connect(function(pp, plr)

if pp.Name == "RobPrompt" then
	
	local robbedAmount = math.random(100, 500)
	
	plr.leaderstats.Cash.Value += robbedAmount
	
	
	pp.Enabled = false
	
	wait(30)
	
	pp.Enabled = true
end

end)

Inside of the ATM is a Group with the parts that the ATM has, and a part that contains the Click Detector, any Idea on how I could add sound to it once someone is done robbing it?

Thanks for any help!

Simply create a sound instance and parent it to the atm, I would parent it to the part they are able to rob from. And then you could use 'sound:Play()` in your script, put it during their robbery/after they finished.

2 Likes

Okay, and where should I put the sound:Play()? In the RobberySystem Script, or? (Yes, I am very goated at scripting)

When you receive the signal do the sound:Play() meaning you’d put it right after the if statement in the ProximityPrompt.Triggered function

1 Like

So basically

local pps = game:GetService(“ProximityPromptService”)

pps.PromptTriggered:Connect(function(pp, plr)
if pp.Name == "RobPrompt" then
	sound:Play()
	local robbedAmount = math.random(100, 500)
	
	plr.leaderstats.Cash.Value += robbedAmount
	
	
	pp.Enabled = false
	
	wait(30)
	
	pp.Enabled = true
end
end)

Okay, right, I did that, but the sound keeps on being underlined (and it doesn’t take any color)

So, I think I’ve just been stupid enough to (probably) put the sound where it’s not supposed to be. I put it INTO the script, is that right?

No “sound” is just an example you have to create the Instance “Sound” and reference it so you can put it in your script. For example: if my sound name was “RobbingSound” i would do script.RobbingSound:Play()

1 Like

Yes You have to have the sound referenced tho you can just play a sound without it being referenced

1 Like

Doesn’t work unfortunately. I put it exactly like you said, and it became blue and all, so I think something still isn’t quiet right?

And I just noticed that it broke the actual robbing script (it doesn’t give the money anymore"

I made this:
https://www.roblox.com/library/9710644800/ATM-Robbery

Hope it helps!

1 Like

No dude dont copy and paste the script im just telling you where to put the soundName:Play()

1 Like

Ah, damn it. Sorry about that. Perfect example that I am goated lol!

1 Like