Tool plays audio and animation upon triggering a proximity prompt

I have a tool that contains a proximity prompt, a animation, an script (obviously) and an sound.

I want to make it so if another player triggers the proximity prompt, the player who is holding the tool plays the animation and the sound.

Some things to mention:

  • The proximity prompt shouldn’t be visible for the player holding the tool
  • My game has a currency system so, I want it to take away 10 money from the player who triggered the proximity and give it to the player who is holding the tool
  • The animation to end upon the sound ending

I have found nothing online about this so this is my last option

Here’s what I’ve tried to use to make it work:

local tool = script.Parent.Parent.Parent
local prox = script.Parent
local sgong = prox.Parent.sgong

tool.Equipped:Connect(function(player)
	
	prox.Enabled = true
	
	prox.Triggered:Connect(function(plr)
		if plr.leaderstats.Money.Value < 10 then
			return
		else
		plr.leaderstats.Money.Value -= 10
		player.Character.leaderstats.Money.Value += 10
		local hum = player.Character.Humanoid
		local anim = hum:LoadAnimation(script.Parent.Animation)
			anim:Play()
			sgong:Play()
			wait(sgong.TimeLength)
			anim:Stop()
			sgong:Stop()
		end
		
	end)
	
end)

If anybody knows how to make this work, I’d be very grateful.

Just tried and it worked on studio (you should test to see if it works in game). Here is what i did:
i have 2 scripts, a local script and a server script

The server script:

local tool = script.Parent
local prom = tool.Handle.ProximityPrompt

tool.Equipped:Connect(function()
	prom.Enabled = true
	
end)

tool.Unequipped:Connect(function()
	prom.Enabled = false
	
end)

prom.Triggered:Connect(function(plr)
	print(plr.Name)
	
end)

The local script:

local tool = script.Parent

tool.Equipped:Connect(function()
	task.wait()
	tool.Handle.ProximityPrompt.Enabled = false
	
end)

The screenshot of the explorer where i have the tool prompt’d:
https://gyazo.com/cdb4dc2d586e8dc5eb86306e24767a6f

ToolPrompted.rbxl (55.9 KB)

here is the place with the prompted tool

The tool does not show the proximity prompt to the tool owner the first time they equip it but the second time it doesn’t work.

my bad, i fixed it with it in the LocalScript:

script.Parent.Handle.ProximityPrompt:Destroy()

Here is the updated place:
ToolPrompted.rbxl (55.8 KB)

I think it works, I’ve tried it on your place and I’ll implement it in my game tomorrow. I’ll let you know if it works. :+1:

1 Like

i will wait to know if it works then :moyai:

It works beautifully, sorry for the late response, I was busy all day. Thank you for the solution for that problem but it doesn’t really solve my main issue. I managed to fix half of it on my own, yet, thank you very much. :smile:

The smell of the solution is even better when we find the solution alone, good job!

1 Like