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.
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