Proximity prompt not showing

I created a proximity prompt inside the player’s humanoidrootpart and I want the proximity prompt to show up only when a player equipped an object and when the proximity prompt show up, the local player proximity prompt shouldn’t show up but instead other player’s proximity prompt should show up. However, when I programmed it, the proximity prompt didn’t show up at all when I equip any tools. May I know what is the problem of this code that I used shown below? (This script is inside a local script not server script because I want the proximity prompt to be showed for a client and not everyone)

local player = game.Players.LocalPlayer
local character = player.Character
local humanoidrootpart = character:WaitForChild("HumanoidRootPart")
while task.wait() do
	if character:FindFirstChildWhichIsA("Tool") then-- and player:GetRankInGroup(6279576)>=5 
		local players = game.Players:GetPlayers()
		for i,v in pairs(players) do
			if v.Name == not player.Name then
				print(v.Name)
				local character = v.Character
				local proximitypromptpart = character:WaitForChild(character.Name.."givetool")
				local proximityprompt = proximitypromptpart:WaitForChild("Givetoolprompt")
				proximityprompt.Enabled = true
				proximityprompt.Triggered:connect(function(player)
					local tool = character:FindFirstChildWhichIsA("Tool")
					tool.Parent = v.Character
				end)
			end
		end
	end
end
1 Like

It appears that the proximity prompt’s activation method is the primary problem. You are attempting to enable the proximity prompt for other players while also determining whether the local player has a tool. But keep in mind that LocalScripts execute separately on every client. This implies that a proximity prompt enabled in one client’s LocalScript will not always show up in the game of another client.

If handled incorrectly, using while task.wait() could result in an infinite loop. Make sure there is a condition to terminate this loop before it ends up running indefinitely. You should use a Script, not a LocalScript, to handle this on the server side if you want the proximity prompt to show for other players but not for the current player. The LocalScripts can then utilize this information to enable or disable prompts as needed.

The server can then notify each client about the status of the proximity prompts. You seem to have iterated over players and checked your tool, however use caution when using the if v.Name == not player.Give the condition a name. If v.Name ~= player, then it ought to be.Name in Lua.

Every time a tool is located, you’re attaching the Triggered event inside the loop. This could result in several connections to the same occurrence, which could result in strange behavior. To prevent links between several events, think about editing this. The way the tool is transferred to v.Character in the Triggered event handler appears to follow logic. But make sure the tool is properly cited and the transfer is permitted by the logic of the game.

To verify that every section of your code is running as intended, use print statements or breakpoints while debugging. This can assist you in determining the possible location of the problem
.
Hope this helps. Have fun and don’t get frustrated, scripting can be hard. Good luck with your scripting journey.

I did the print statement at the if v.Name == not player.Name and nothing came out so I suspect that it has something wrong with that if statement but idk what is wrong. I personally use a local script because i only want the proximity prompt to appear for the local player when they equip the tool and not everyone. So, what should I do instead?

Based on your explanation, the issue indeed seems to be with the if statement if v.Name == not player.Name. In Lua, the correct way to compare two values for inequality is using ~=, not == not. So, the correct form of your condition should be if v.Name ~= player.Name.

Change if v.Name == not player.Name then to if v.Name ~= player.Name then .

Since you want the proximity prompt to appear only for the local player when they equip a tool, you should monitor the local player’s character for a tool being equipped.

You need to ensure that the proximity prompt is associated with the correct object or character part and that it is enabled or disabled based on the tool’s status.

local player = game.Players.LocalPlayer

-- Function to handle tool equipped
local function onToolEquipped(tool)
    for _, otherPlayer in pairs(game.Players:GetPlayers()) do
        if otherPlayer ~= player then
            local otherCharacter = otherPlayer.Character
            if otherCharacter then
                local proximityPromptPart = otherCharacter:FindFirstChild("givetool")
                if proximityPromptPart then
                    local proximityPrompt = proximityPromptPart:FindFirstChild("Givetoolprompt")
                    if proximityPrompt then
                        proximityPrompt.Enabled = true
                    end
                end
            end
        end
    end
end

-- Monitor for tool being equipped
player.Character.ChildAdded:Connect(function(child)
    if child:IsA("Tool") then
        onToolEquipped(child)
    end
end)

-- You can also monitor for tool being unequipped to disable the prompt, if needed

We define a function onToolEquipped that is called whenever a tool is added to the player’s character. The function iterates through all other players and enables the proximity prompt on a specific part (givetool) if it exists. This setup ensures that the proximity prompt is only manipulated for the local player and only when they have a tool equipped. Ensure that your game structure supports this logic, especially the naming and presence of the givetool parts and Givetoolprompt objects.

Hope this helps, good luck.

sir using chatgpt is not how to be a good guy on devforum. anyways

@flxvershellyqs your prompt might not be working because of the properties. only thing i can say enable the RequiresLineOfSight or change the maxactivationdistance.

otherwise its a problem with the code

1 Like

I did not know how to respond to the question, so I just asked ChatGPT since I figured it would probably know.

Then you shouldn’t even respond to the question in the first place (I’m not meant to be rude, sorry if it did)

Try proximityprompt.RequiresLineOfSight = false and it should be fixed

Edit: meant to reply to @flxvershellyqs

Oh sorry, I am just relatively new on the Forums and I was trying to help a feller. I am still not familiar to the rules, that was my bad.

I changed it and it is working rn however, I am having problems when the character resets because when the players reset their character, the prompt didn’t show up as it isn’t enabled due to the while loop breaking. May I know how do I do to solve this problem?

btw the prompt still remains in their character it just didn’t show up locally

Here is my current code in the local script

local player = game.Players.LocalPlayer
local character = player.Character
local humanoidrootpart = character:WaitForChild("HumanoidRootPart")
while task.wait() do
	if character:FindFirstChildWhichIsA("Tool") then --and player:GetRankInGroup(6279576)>=5 
		local players = game.Players:GetPlayers()
		for i,v in pairs(players) do
			if v.Name ~= player.Name then
				print(v.Name)
				local character = v.Character
				local proximitypromptpart = character:WaitForChild(character.Name.."givetool")
				local proximityprompt = proximitypromptpart:WaitForChild("Givetoolprompt")
				proximityprompt.Enabled = true
			end
		end
	else
		local players = game.Players:GetPlayers()
		for i,v in pairs(players) do
			local character = v.Character
			local proximitypromptpart = character:WaitForChild(character.Name.."givetool")
			local proximityprompt = proximitypromptpart:WaitForChild("Givetoolprompt")
			proximityprompt.Enabled = false
		end
	end
end