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?
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.
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 . 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.