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

I want an NPC to give me sword when I speak to him how can I do that?

i want the NPC to give you a sword on his first diolauge but it is a GUI dialouge how do i do that?

here is what i have:

local clickDetector = workspace.NPCS.Hardquest8.givesword

function onMouseClick()

local function giveTool(player, tool) local backpack = player:FindFirstChildOfClass("Backpack") if backpack then game.SeverStorage.Katana.Parent = backpack end end wait(5)

end

clickDetector.MouseClick:connect(onMouseClick)

and the dialouge(the dialouge works):script.Parent.Visible = false

local clickDetector = workspace.NPCS.Hardquest8.ClickDetector

function onMouseClick() script.Parent.Visible = true script.Parent.Text = ("sighs hey you going into the wild? Take this and thank me later") wait(5) script.Parent.Text = ("hey also take this book it's important. ") wait(4) script.Parent.Text = ("see you on the other side!") wait(1) script.Parent.Visible = false end

clickDetector.MouseClick:connect(onMouseClick)

1 comment

0

Please Fix your Writing so i can understand

2 answers

✓ Accepted answer

If you want to give a Player a Tool, You can use :Clone()!

Script:

script.Parent.MouseClick:Connect(function(plr)
       local Give = game.ServerStorage:FindFirstChild("Your Tool Name") -- Search for The Tool
       Give:Clone() -- Clone The Tool
       Give.Parent = plr.Backpack -- Move The Cloned Item to Player Backpack
end)

Hope It Helps!

2 comments

0

thanks man!

0

@maxthebeast662 Np

Alright so basically in your code you made it so that the katana gets moved to the players backpack. If the player dies, then if they do the dialogue again the katana won’t be given since it was moved out of it’s parent to your backpack. We can prevent this by doing Clone:().

local ClickDetector = workspace.NPCS.Hardquest8.givesword

local function giveTool(player, tool)
      if player.Backpack.Katana then -- Checking if a katana is already there
            return -- Making the code not run if a katana is there
       else -- If the katana is not there then
              game.ServerStorage.Katana:Clone().Parent = player.Backpack -- Cloning the katana     into the players backpack
             end
      end
end

clickdetector.MouseClick:Connect(onMouseClick)
clickdetector.MouseClick:Connect(giveTool)

If code does not work then let me know

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