Help with and operators

Using this script in which it is detected whether or not your tool is equipped, and if it is equipped, it will enable this proximity prompt. It worked until I added the and prompt.Installed.Value == false and prompt.Bolted.Value == false then line. Installed and Bolted are Boolvalues I put inside the prompt.

local PPS = game:GetService("ProximityPromptService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer

local function ToolEquipped(prompt)
	local tool = player.Character:FindFirstChildWhichIsA("Tool")
	if tool ~= nil then
		prompt.Enabled = true
	end
end

local function CheckPrompt(prompt)
	if prompt.Name == "Front Left Wheel" and prompt.Installed.Value == false and prompt.Bolted.Value == false then
		if player.Character:FindFirstChildWhichIsA("Tool") ~= nil then
			prompt.Enabled = true
		else
			prompt.Enabled = false
			player.Character.ChildAdded:Connect(function()
				ToolEquipped(prompt)
			end)
		end
	end
end

PPS.PromptShown:Connect(CheckPrompt)

I’m assuming the issue is that either Installed.Value or Bolted.Value is false.
Can you please print out the values of them just prior to the if statement to confirm this?

Hello! Based on your description, it seems that you want to determine whether the tool is equipped, and if so, activate the approach request based on the values of the Installed and Bolted properties. There are a few things that can be improved or fixed in your code.

Here are some recommendations and an example of a corrected version of the script:

  • Make sure that the Installed and Bolted properties of the Prompt object are actually set and are boolean values.
  • In the CheckPrompt function, the properties should be checked every time it is called, not just once.
  • It may be worth adding handlers for changing the Installed and Bolted properties to dynamically update the state.

Updated example:

local PPS = game:GetService("ProximityPromptService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer

local function ToolEquipped(prompt)
    local tool = player.Character and player.Character:FindFirstChildWhichIsA("Tool")
    if tool ~= nil then
        prompt.Enabled = true
    else
        prompt.Enabled = false
    end
end

local function CheckPrompt(prompt)
    if prompt.Name == "Front Left Wheel" then
        -- Предполагается, что Installed и Bolted — это BoolValue внутри prompt
        if prompt.Installed.Value == false and prompt.Bolted.Value == false then
            local hasTool = player.Character and player.Character:FindFirstChildWhichIsA("Tool")
            if hasTool then
                prompt.Enabled = true
            else
                prompt.Enabled = false
                -- Обработка добавления инструмента
                player.Character.ChildAdded:Connect(function(child)
                    if child:IsA("Tool") then
                        ToolEquipped(prompt)
                    end
                end)
            end
        else
            prompt.Enabled = false
        end
    end
end

PPS.PromptShown:Connect(CheckPrompt)

If the Installed and Bolted properties can change during the game, you should add listeners for their changes to update the prompt.Enabled state in real-time.

If you want, I can help you more specifically by providing the structure of the Prompt object or clarifying how you set the Installed and Bolted properties.

1 Like

Hi!
image
This is how it looks. The script seems to work sometimes however when I test by changing the values ingame, it doesn’t seem to work anymore.

The values would change ingame when the prompt has been used. The Installed and Bolted properties would be false before using the prompt, and after it has been used it would change to true. I want it so that it when it becomes false, the prompt doesn’t activate even when the tool is equipped nearby

Hi again!
I understand. You need the tooltip to be activated only when the Installed and Bolted properties are false, and the character has the tool. It’s also important for the script to respond to changes in these properties in real-time, rather than just when the tooltip appears.

Here’s what I recommend you do:

  • Subscribe to changes of Installed and Bolted properties of the tool.
  • Update tooltip state when these properties change.
  • Check if the character has the tool.

An example of an updated script:

local PPS = game:GetService("ProximityPromptService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer

local function updatePrompt(prompt, tool)
    if not tool then
        prompt.Enabled = false
        return
    end

    local installed = tool:FindFirstChild("Installed")
    local bolted = tool:FindFirstChild("Bolted")

    if installed and bolted then
        if not installed.Value and not bolted.Value then
            prompt.Enabled = true
        else
            prompt.Enabled = false
        end
    else
        -- If no properties are found, disable the hint
        prompt.Enabled = false
    end
end

local function monitorToolProperties(tool, prompt)
    local installed = tool:FindFirstChild("Installed")
    local bolted = tool:FindFirstChild("Bolted")

    if installed then
        installed:GetPropertyChangedSignal("Value"):Connect(function()
            updatePrompt(prompt, tool)
        end)
    end
    if bolted then
        bolted:GetPropertyChangedSignal("Value"):Connect(function()
            updatePrompt(prompt, tool)
        end)
    end
end

local function checkAndSetPrompt(prompt)
    local character = player.Character
    if not character then return end

    local tool = character:FindFirstChildWhichIsA("Tool")
    if not tool then
        prompt.Enabled = false
        return
    end

    -- Checking the properties
    local installed = tool:FindFirstChild("Installed")
    local bolted = tool:FindFirstChild("Bolted")
    if installed and bolted then
        -- Subscribe to the changes
        monitorToolProperties(tool, prompt)
        -- We update it immediately
        updatePrompt(prompt, tool)
    else
        prompt.Enabled = false
    end
end

-- Processing the addition of the tool
player.Character.ChildAdded:Connect(function(child)
    if child:IsA("Tool") then
        local prompt = PPS.Prompts["Front Left Wheel"] -- replace with the current name checkAndSetPrompt(prompt)
    end
end)

-- Processing the removal of the tool
player.Character.ChildRemoved:Connect(function(child)
    if child:IsA("Tool") then
        local prompt = PPS.Prompts["Front Left Wheel"]
        prompt.Enabled = false
    end
end)

-- Initially, if the tool is already present at startup
local character = player.Character
if character then
    local prompt = PPS.Prompts["Front Left Wheel"]
    local tool = character:FindFirstChildWhichIsA("Tool")
    if tool then
        checkAndSetPrompt(prompt)
    end
end

-- Handling an event when the prompt is displayed
PPS.PromptShown:Connect(function(prompt)
    if prompt.Name == "Front Left Wheel" then
        local character = player.Character
        if character then
            local tool = character:FindFirstChildWhichIsA("Tool")
            if tool then
                -- Updating the status
                checkAndSetPrompt(prompt)
            else
                prompt.Enabled = false
            end
        end
    end
end)

Key points:

  • The script subscribes to the Installed and Bolted properties to automatically update the tooltip status.
  • The tool availability check occurs when a tool is added or removed from a character.
  • The tooltip is only activated if both properties are set to false.

If you have any questions or need additional configuration, please let us know!

are you fr using ai to answer lol

1 Like

not really, I take all the information and use it to create a solution and identify the causes of the problem.

dada poveril (net)

helping using ai is not always accurate, thats the problem

1 Like

You’re clearly straight up using AI to answer the question.
It’s obvious that you’re not just using it as a tool, but as a replacement for you.

This is not how you help people. At the very least, you should formulate the answer by yourself, or the other way around.

1 Like

Are you referring to changing the values in the explorer versus doing so in the script?

Can you elaborate on what you mean with when the tool is equipped nearby?

Nested signal connections are generally a bad idea, a new connection is made to the inner signal each time the outer signal is fired.

local connection
local function CheckPrompt(prompt)
	if prompt.Name == "Front Left Wheel" and prompt.Installed.Value == false and prompt.Bolted.Value == false then
		if player.Character:FindFirstChildWhichIsA("Tool") ~= nil then
			if connection then --if connection exists then
				connection:Disconnect() --disconnect existing connection
				connection = nil --clear existing connection
			end
			prompt.Enabled = true
		else
			prompt.Enabled = false
			if connection == nil then --if no connection exists
				connection = player.Character.ChildAdded:Connect(function() --create a new connection
					ToolEquipped(prompt)
				end)
			end
		end
	end
end