Help switching from click to E prompt

I have a script that works by clicking the item to pick it up. This is the script.

local ClickDetector = script.Parent.ClickDetector
local sound = script.Parent.pickup
local debounce = false

ClickDetector.MouseClick:Connect(function(player)
	
	if debounce then return end
	
	debounce = true
	
	player.leaderstats.Rubies.Value = player.leaderstats.Rubies.Value + script.Parent.Rubies.Value
	sound:Play()
	wait(1)
	script.Parent:Destroy()
			
end)

I want to change the click to a E prompt key to pick up the item. I have modified the script to this, but it doesnt work for some reason. I can see the prompt but it doesnt actually take the item.

local ClickDetector = script.Parent.ClickDetector
local sound = script.Parent.pickup
local debounce = false
local prompt = script.Parent.ProximityPrompt

prompt.Triggered:Connect(function(player)
	
	if debounce then return end
	
	debounce = true
	
	player.leaderstats.Rubies.Value = player.leaderstats.Rubies.Value + script.Parent.Rubies.Value
	sound:Play()
	wait(1)
	script.Parent:Destroy()
			
end)

The lines I added are.

local prompt = script.Parent.ProximityPrompt

prompt.Triggered:Connect(function(player)

Any ideas why this doesnt work after I change it to prompt?

It seems to work for me? Is any error coming up in console when you run the game? (Press F9)
Gif - https://cdn.discordapp.com/attachments/889585208704262154/897641342757384242/capture.gif
Code -

local Players = game:GetService("Players")

local ClickDetector = script.Parent.ClickDetector
local sound = script.Parent.pickup
local debounce = false
local prompt = script.Parent.ProximityPrompt

prompt.Triggered:Connect(function(player)

	if debounce then return end

	debounce = true

	player.leaderstats.Rubies.Value = player.leaderstats.Rubies.Value + script.Parent.Rubies.Value
	sound:Play()
	wait(1)
	script.Parent:Destroy()
	
	print("Rubies - "..player.leaderstats.Rubies.Value)
end)

Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local rubies = Instance.new("IntValue")
	rubies.Name = "Rubies"
	rubies.Parent = leaderstats
end)

Thanks checking this right now.

My code is identical to yours, I just added a mock function that creates your leaderstats that you have.

Now that I remember however, a while ago I experienced a Roblox bug where if I teleported the player by changing their HumanoidRootParts Position instead of their CFrame, ProximityPrompts would not work for them. You wouldn’t happen by any chance to be changing the HumanoidRootParts Position at any point in the game? This could be breaking it.

I am using moprhs that change my character, but prompts are working correctly on a dialog text I am working on.

yeah there is no error, it just doesnt do anything on click. Strange.

local ClickDetector = script.Parent.ClickDetector
local sound = script.Parent.pickup
local debounce = false
local prompt = script.Parent.ProximityPrompt

prompt.Triggered:Connect(function(player)
	
	if not debounce == true then
	
	debounce = true
	
	player.leaderstats.Rubies.Value = player.leaderstats.Rubies.Value + script.Parent.Rubies.Value
	sound:Play()
	wait(1)
	script.Parent:Destroy()
          debounce = false
	end		
end)

Yeah that is strange :frowning: . As I mentioned my experience of ProximityPrompts hasn’t been positive either they seem to be very buggy. Could you try running my script in an empty place? If you can’t find a solution then the only workaround I can think of is creating your own ProximityPrompt system using magnitude checks. I also suggest you create a reproduction file and report the bug in the bug report section.

Oh haha I it worked the whole time. It just doesnt work in studio. Works fine after published. Well thanks for the help.

1 Like