ProximityPrompt not detecting player

I am trying to make a script that adds a tool to a player’s inventory when used.

I used print to print who activated the script, and it kept returning “nil”, even when a player presses it. Also in the “ProxPrompt.Triggered:Connect(harvest(player))” line, the player variable is underlined in red and said to be an “unknown” global when hovering my cursor over it.

I have searched for help on the forum: I tried replacing player with uppercase Player, Plr, plr… and none seems to work.

here’s the script:

local ProximityPromptService = game:GetService("ProximityPromptService")
local fruit = script.Parent.Parent
local ProxPrompt = script.Parent
local function harvest(player)
	script.Parent.Parent.Transparency = 1
	script.Parent.Parent.CanCollide = false
	script.Parent.Enabled = false
	print(player)
	
	wait(10)
	
	script.Parent.Parent.Transparency = 0
	script.Parent.Parent.CanCollide = true
	script.Parent.Enabled = true
end

ProxPrompt.Triggered:Connect(harvest(player))
1 Like

:Connect() accepts one parameter, and that’s the callback function. Any parameters passed when the event occurs are sent automatically.

prompt.Triggered:Connect(harvest)
local function harvest(player) end
prompt.Triggered:Connect(function(player) harvest(player) end) --> two functions
local function harvest(player) end

I also suggest you use task.wait() in place of old wait().

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.