Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

NPC talks when you're holding a tool How?

Asked by
vxnnisu 17
2 years ago

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.

0
Is the script a local script? Where is the NPC located, i need to know to help. LordKrox 39 — 2y
0
its a normal script. the npc is in workspace vxnnisu 17 — 2y
0
Ah, well i was too late anyways, i hope you succeed in making your game, it seems like a cool game. LordKrox 39 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

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

0
This worked! Thank you so much. You will be credited vxnnisu 17 — 2y
0
Np. AProgrammR 398 — 2y
Ad

Answer this question