I’m making an interact script and I want a selectionbox to appear when the player is in range the proximity prompt. The problem is that the promptshown event is not firing. Here is the script:
while true do
local clone = script.NPC:Clone()
clone.Parent = workspace
clone.LowerTorso.CFrame = game:GetService("Workspace").NPCSpawn.CFrame
clone.FindSeat:Fire()
local prompt = Instance.new("ProximityPrompt")
prompt.Parent = clone.UpperTorso
prompt.GamepadKeyCode = Enum.KeyCode.ButtonX
prompt.KeyboardKeyCode = Enum.KeyCode.E
prompt.PromptShown:Connect(function()
clone.SelectionBox.Adornee = clone
clone.SelectionBox.Visible = true
end)
prompt.PromptHidden:Connect(function()
clone.SelectionBox.Visible = false
end)
wait(8)
end
I recently encountered the same issue, to fix it I did:
prompt.RequiresLineOfSight = false;
This worked for me because the prompt was never showing up to begin with, I was also working on an NPC and parented the prompt to the UpperTorso, where it’s pretty hard for you to be in the direct line of sight for the prompt.
If this doesn’t work, it’s worth a try to change the MaxActivationDistance property to something higher.
A part of this has to be on the client, so mabye try adding each NPC you generate to a folder. Then have a LocalScript which checks for when an NPC is added, adds a new prompt, and then connect the events:
--Server
--The server script is simply responsible for adding the npcs to the npc folder
local npcFolder = the folder you are adding them to
while true do
local clone = script.NPC:Clone();
clone.Parent = npcFolder;
clone.LowerTorso.CFrame = game:GetService("Workspace").NPCSpawn.CFrame;
clone.FindSeat:Fire();
wait(8);
end;
--Client
local npcFolder = the folder the npcs are being added to
npcFolder.ChildAdded:Connect(function(npc)
local prompt = Instance.new("ProximityPrompt");
prompt.Parent = npc.UpperTorso;
prompt.GamepadKeyCode = Enum.KeyCode.ButtonX;
prompt.KeyboardKeyCode = Enum.KeyCode.E;
prompt.PromptShown:Connect(function()
--whatever u want to happen when the prompt is shown
end);
prompt.PromptHidden:Connect(function()
--whatever u want to happen when the prompt is hidden
end);
end);
I may have mispelled “prompt” a lot, for whatever reason I can never spell it right lol