Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is there a way to have an NPC say a separate dialog if the player has a tool?

I want to make a NPC using the Dialog object (If possible) that if you have a certain tool the NPC says one thing but if you don't have the tool says another thing. I have tried lots of things but nothing seems to work. The script is located inside of a bunch of models and folders in workspace. The script is NOT a module or local script.

Here is what I tried:

local Tool = game.Players.LocalPlayer.Backpack:GetChildren() --[[ Creates a table of all the objects inside the players backpack]]--

-- Creates a function that checks if the player has of does not have the tool
local function dialog()
-- Loops around the players backpack
	for i, v in pairs(Tool) do
		print(v)
		
		-- Checks if v is == the tool (The tool is named "Artifact")
		if v.Name == "Artifact" and v:IsA("Tool") then
			print("You have the tool")
			-- Changes the dialog 
			script.Parent.InitialPrompt = "You found it! Take it to the gate to open it."
		else 
			-- Changes the dialog if the player does not have the tool
			script.Parent.InitialPrompt = "I don't see an artifact! You need the artifact to get in!"
		end
	end
	
end

-- Checks if the dialog is in use. If it is then the function above will run
if script.Parent.InUse == true then
	dialog()
end

I don't know if this is possible without coding my own dialog system but if there is a way then please help!

Any help appreciated! Thanks!

1 answer

✓ Accepted answer

The reason why it won't work may be because there are other tools after it.

local Tool = game.Players.LocalPlayer.Backpack:GetChildren()
local function dialog()	
	local oof
	for i, v in pairs(Tool) do
	        print(v)
	        if v.Name == "Artifact" and v:IsA("Tool") then
			oof = true
        	end
    	end
	if var == true then
            print("You have the tool")
            -- Changes the dialog 
            script.Parent.InitialPrompt = "You found it! Take it to the gate to open it."
        else 
            -- Changes the dialog if the player does not have the tool
            script.Parent.InitialPrompt = "I don't see an artifact! You need the artifact to get in!"
        end
end

if script.Parent.InUse == true then
    dialog()
end

I hope this helped!

2 comments

0

Thanks! I will try this out!

0

Np :D

This discussion is preserved as it was. New answers, comments, and votes are closed.