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

NPC talks when you're holding a tool How?

Hello there! I was making a game where you give an npc a teddy bear and they say thanks to you. I've been trying to make a piece of code where when you're holding the tool in your inventory, the npc sensors it and talks to you. Can someone fix up this code for me? Thank you and whoever helps me with this will be in the credits.

local NPC = script.Parent.Parent
local CC = Enum.ChatColor.Red
local proximityprompt = script.Parent.Block.ProximityPrompt
local function Chat(message: string, color)
	game:GetService("Chat"):Chat(NPC.Head, message, CC)
end
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character

proximityprompt.Triggered:Connect(function(player)
	if character:FindFirstChild("teddytool") then
		Chat("test")
	end
end)

Appreciate it.

3 comments

0

Is the script a local script? Where is the NPC located, i need to know to help.

0

its a normal script. the npc is in workspace

0

Ah, well i was too late anyways, i hope you succeed in making your game, it seems like a cool game.

1 answer

✓ Accepted answer

If this is a localscript, you can't use .triggered (I think) Make it a script

OR

If this is a script, you don't need to do 'Players.LocalPlayer'

Use:

local NPC = script.Parent.Parent
local CC = Enum.ChatColor.Red
local proximityprompt = script.Parent.Block.ProximityPrompt
local function Chat(message: string, color)
    game:GetService("Chat"):Chat(NPC.Head, message, CC)
end

proximityprompt.Triggered:Connect(function(player)
	local character = player.Character
    if character:FindFirstChild("teddytool") then
        Chat("test")
    end
end)

Players.LocalPlayer can only be used client-sided

2 comments

0

This worked! Thank you so much. You will be credited

0

Np.

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