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

NPC won't give item even with required KOs?

My NPC's won't give items that people want, even when they have the required KOs (1), the script is a LocalScript, the items are inside ReplicatedStorage - Game_Tools - Food, and the NPC is inside the Workspace. The script looks okay, but I'm confused why it won't work. It doesn't even remove 1 KO to give you the item. No errors either.

local function select(p,d)
local ko = p.leaderstats.KOs
if ko.Value >= 1 then
ko.Value = ko.Value - 1
local item = game.ReplicatedStorage.Game_Tools.Food:findFirstChild(d.Name)
local new = item:clone()
new.Parent = p.Backpack
end end
script.Parent.DialogChoiceSelected:connect(select)

4 comments

0

select() is a core Lua function name, you should probably use a different name and see if it works.

0

Hi, On line 5 you should say :findFirstChild("d.Name"), that is the proper way to use it..

0

They're trying to access the Name property of variable d, right? So if you added quotes it wouldn't access the variable.

0

Changing it to that made no difference?

2 answers

Try if this works, I'm a noob myself.

local function select(p,d)
local ko = player.leaderstats.KOs
local item = game.ReplicatedStorage.Game_Tools.Food
local player = script.Parent.Parent.Parent.Parent -- change the final Parent to Workspace.
if ko.Value >= 1 then
ko.Value = ko.Value - 1
item:Clone().Parent = player.Backpack
end end
script.Parent.DialogChoiceSelected:connect(select)

6 comments

0

Says "unknown global player" in line 2

0

whoop sorry, move line 4 to line 2

0

Still isn't working. :c I got the one line like this "script.Parent.Parent.Parent.Workspace"

0

Where did you put the script..? By the way, if you want a made model, I will give you one, but you'll have to change things inside yourself

0

The Script is located inside of a Dialog, which is located inside of a brick called "Dialog". And that might help.

0

:C


local function select(p,d)
local item = game.ReplicatedStorage.Game_Tools.Food
local player = game.Players.LocalPlayer --Add ".Character" if it is what you needed 
local ko = player.leaderstats.KOs
if ko.Value >= 1 then
ko.Value = ko.Value - 1
item:Clone().Parent = player.Backpack
end end
script.Parent.DialogChoiceSelected:connect(select)



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