How to use proximity prompt for tycoon button

Hello! I need help with a proximity prompt, when we hold it, it will purchase a dropper, how do I do this?

Capture

here is what is inside the main script

— Buying Functions —

for i,v in pairs(Buttons:GetChildren()) do
local NewItem = BoughtItems:FindFirstChild(v.Item.Value)
if NewItem ~= nil then
items[NewItem.Name] = NewItem:Clone()
NewItem:Destroy()
else
v.ButtonPart.Transparency = 1
v.ButtonPart.CanCollide = false
end
if v:FindFirstChild(“Dependency”) then
coroutine.resume(coroutine.create(function()
v.ButtonPart.Transparency = 1
v.ButtonPart.CanCollide = false
if BoughtItems:WaitForChild(v.Dependancy.Value, 100000) then
v.ButtonPart.Transparency = 0
v.ButtonPart.CanCollide = true

		end
	end))
end

v.ButtonPart.Touched:Connect(function(Hit)
	if Hit.Parent:FindFirstChild("Humanoid") then
		local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
		if Values.OwnerValue.Value == Player then
			if v.ButtonPart.CanCollide == true and v.ButtonPart.Transparency == 0 then
				if Player:WaitForChild("leaderstats").Cash.Value >= v.Price.Value then
					Player.leaderstats.Cash.Value -= v.Price.Value
					items[v.Item.Value].Parent = BoughtItems
					v:Destroy()
				end
			end
		end
	end
end)

end

I’m really new to scripting :frowning:

Ok so for what your asking about first of all I would suggest reading amount Proximity Prompts if you are new to them. (it contains everything about them and you can find what ur looking for in there)

https://developer.roblox.com/en-us/api-reference/class/ProximityPrompt

To make it more simple for you look at this event you can use with ProximityPrompts. This is what you are looking for. Just put the code you have already in a function and run the function (or the other way you could do it is just link a function directly to it)

ProximityPrompt.Triggered (roblox.com)

1 Like

You would add a function called Triggered

ProximityPrompt.Triggered:Connect(function()
 -- Buy function
end)

Inside the function, put in your duplication code and everything will work perfectly! If you want it so that the player has press and hold, there are settings in the properties tab!

(Be sure to actually define where the ProximityPrompt resides!)

By the way it is end) not ) at the end.

1 Like

Incorrect! It is basic knowledge really to know that and also if you take a look inside the code that Roblox has even provided it states that. Please only state information which is correct cuz it will confuse some people.
(I know it is not the same code but it is the same format. If you don’t put the end) you will get an error.

Just to let you know that it was before a ( on the end until I told him to change it! and he then edited it.

Yes. I did edit it! Thanks to you of course!

(post withdrawn by author, will be automatically deleted in 1 hour unless flagged)

When I original posted, I wrote the function as this:

proximityPrompt.Triggered:Connect(function()
 -- Code here
) -- See how I didn't put an end) here? 

It was supposed to be:

proximityPrompt.Triggered:Connect(function()
 -- Code here
end) -- See how I put and end) here?
1 Like