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

NPC won't give item even with required KOs?

Asked by 6 years ago

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)
0
select() is a core Lua function name, you should probably use a different name and see if it works. User#17862 0 — 6y
0
Hi, On line 5 you should say :findFirstChild("d.Name"), that is the proper way to use it.. iSvenDerp 233 — 6y
0
They're trying to access the Name property of variable d, right? So if you added quotes it wouldn't access the variable. User#17862 0 — 6y
0
Changing it to that made no difference? LuckyAura -1 — 6y

2 answers

Log in to vote
0
Answered by
0msh 333 Moderation Voter
6 years ago
Edited 6 years ago

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)
0
Says "unknown global player" in line 2 LuckyAura -1 — 6y
0
whoop sorry, move line 4 to line 2 0msh 333 — 6y
0
Still isn't working. :c I got the one line like this "script.Parent.Parent.Parent.Workspace" LuckyAura -1 — 6y
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 0msh 333 — 6y
View all comments (2 more)
0
The Script is located inside of a Dialog, which is located inside of a brick called "Dialog". And that might help. LuckyAura -1 — 6y
0
:C LuckyAura -1 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

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)

Answer this question