Changing touch connect to proximity prompt

I am having trouble changing this touch connect script to a proximity prompt. Here is the touch connect.

local b = script.Parent
local scroll_note = b:WaitForChild'scroll_note'
b.Touched:connect(function(hit)
	local c = hit.Parent
	if c then
		local p = game.Players:GetPlayerFromCharacter(c)
		if p then
			if not p.PlayerGui:FindFirstChild("scroll_note") then
				local g = scroll_note:Clone()
				g.cutoff.Frame.scroll.TextLabel.TextWrapped = true
				g.cutoff.Frame.scroll.TextLabel.Text = text
				local newscript = g:WaitForChild("scroll_note")
				g.Parent = p.PlayerGui
				newscript.Disabled = false
			end
		end
	end
end)

I tried changing it to this and the prompt wont open.

local b = script.Parent
local scroll_note = b:WaitForChild'scroll_note'
local prompt = script.Parent.ProximityPrompt

prompt.Triggered:Connect(function(hit)
	local c = hit.Parent
	if c then
		local p = game.Players:GetPlayerFromCharacter(c)
		if p then
			if not p.PlayerGui:FindFirstChild("scroll_note") then
				local g = scroll_note:Clone()
				g.cutoff.Frame.scroll.TextLabel.TextWrapped = true
				g.cutoff.Frame.scroll.TextLabel.Text = text
				local newscript = g:WaitForChild("scroll_note")
				g.Parent = p.PlayerGui
				newscript.Disabled = false
			end
		end
	end
end)

ProximityPrompt.Triggered’s event returns the player, not the character part.

(hit is the player not one of it’s parts)

Code Solution if you really cant figure out how it works
prompt.Triggered:Connect(function(p)
  if not p.PlayerGui:FindFirstChild("scroll_note") then
    local g = scroll_note:Clone()
    g.cutoff.Frame.scroll.TextLabel.TextWrapped = true
    g.cutoff.Frame.scroll.TextLabel.Text = text
    
    local newscript = g:WaitForChild("scroll_note")
    g.Parent = p.PlayerGui
    newscript.Disabled = false
  end
end)
2 Likes
local b = script.Parent
local scroll_note = b:WaitForChild'scroll_note'
b.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("HumanoidRootPart") then
		local char = hit.Parent
		if char then
			local plr = game.Players:GetPlayerFromCharacter(char)
			if plr then
				if not plr:FindFirstChild("PlayerGui"):FindFirstChild("scroll_note") then
					local gui = scroll_note:Clone()
					gui.cutoff.Frame.scroll.TextLabel.TextWrapped = true
					gui.cutoff.Frame.scroll.TextLabel.Text = "" --replace with some text
					local newscript = gui:WaitForChild("scroll_note")
					gui.Parent = plr.PlayerGui
					newscript.Disabled = false
				end
			end
		end
	end
end)
local gui = script.Parent
local scroll_note = gui:WaitForChild("scroll_note")
local prompt = script.Parent:WaitForChild("ProximityPrompt")

prompt.Triggered:Connect(function(plr)
	if plr then
		if not plr:FindFirstChild("PlayerGui"):FindFirstChild("scroll_note") then
			local snClone = scroll_note:Clone()
			gui.cutoff.Frame.scroll.TextLabel.TextWrapped = true
			gui.cutoff.Frame.scroll.TextLabel.Text = "" --change to text
			local newscript = gui:WaitForChild("scroll_note")
			gui.Parent = plr.PlayerGui
			newscript.Disabled = false
		end
	end
end)

As the previous reply stated whenever a prompt is triggered the player object pertaining to the player which triggered the prompt (causing the event to fire) is automatically passed as an argument to any function connected to the event.

More info here:
https://developer.roblox.com/en-us/api-reference/event/ProximityPrompt/Triggered

I’d like it if you didn’t copy-paste my post but I digress

I don’t believe I did but I digress.