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

How do you give a player a tool if they say a certain word?

Asked by 7 years ago

I am trying to make a script where if a player says a certain word they will get a tool. For example, if a player says sword, they will get a sword in their backpack. This is what I have so far.

local tools = game.Lighting.Sword
local tool = game.Lighting.Bow
local input = script.Parent.TextBox
local output = script.Parent.TextLabel

local function raw_input(prompt)
    local text = ""
    output.Text = prompt
    input:CaptureFocus()
    local event = input.FocusLost:connect(function(enterPressed)
        if enterPressed and input.Text ~= "" then
            text = input.Text
        else
            input:CaptureFocus()
        end
    end)
    repeat wait() until text ~= ""
    return text
end
-------------------------------------------------Dialogue---------------------------
local response = raw_input("What is your name?")
    output.Text = "Hello, " .. response .. "!"

repeat wait(2) until text ~= ""

    response = raw_input("Would you like to go on a quest?")
    output.Text = "" .. response .. "? You didn't have a choice. It was always going to be yes."

    wait(3)

    response = raw_input("You will need a weapon. Would you like a bow or sword?")
    if input.Text == "bow" or input.Text == "sword" or input.Text == "Sword" or input.Text == "Bow" then
        output.Text = "Great choice! I knew you would pick the " .. response .. "!"
    else
        response = raw_input("What? What is a " .. response .. "? Please pick a sword or bow.")
        output.Text = "Great choice! I knew you would pick the " .. response .. "!"
    end

            if input.Text == "sword" or input.Text == "Sword" then
                tools:Clone().Parent = player.Backpack
            end

            if input.Text == "Bow" or input.Text == "bow" then
                tool:Clone().Parent = player.Backpack
            end
0
Don't use Lighting to store tools, use ServerStorage or ReplicatedStorage starlebVerse 685 — 7y

1 answer

Log in to vote
0
Answered by
Etheroit 178
7 years ago
Edited 7 years ago

I made some fixes :) and it will work PS You can use lighting service. ServerStorage will not work probably ( it will not work if you have got FilteringEnabled ( game.Workspace ) ) ReplicatedStorage is using to use things first.

local tools = game.Lighting
local input = script.Parent.TextBox
local output = script.Parent.TextLabel
local player = game.Players.LocalPlayer

local function raw_input(prompt)
    local text = ""
    output.Text = prompt
    input:CaptureFocus()
    local event = input.FocusLost:connect(function(enterPressed)
        if enterPressed and input.Text ~= "" then
            text = input.Text
        else
            input:CaptureFocus()
        end
    end)
    repeat wait() until text ~= ""
    input.Text = ""
    return text
end
-------------------------------------------------Dialogue---------------------------
local response = raw_input("What is your name?")
output.Text = "Hello, " .. response .. "!"

wait(2)

response = raw_input("Would you like to go on a quest?")
output.Text = "" .. response .. "? You didn't have a choice. It was always going to be yes."

wait(2)

response = raw_input("You will need a weapon. Would you like a bow or sword?")

if string.upper(response) == "BOW" then
      output.Text = "Great choice! I knew you would pick the bow!"
      tools.Bow:Clone().Parent = player.Backpack
elseif string.upper(response) == "SWORD" then
      output.Text = "Great choice! I knew you would pick the sword!"
      tools.Sword:Clone().Parent = player.Backpack
else
      while true do
           response = raw_input("What? What is a " .. response .. "? Please pick a sword or bow.")
           if string.upper(response) == "BOW" then
                output.Text = "Great choice! I knew you would pick the bow!"
                tools.Bow:Clone().Parent = player.Backpack
                break
           elseif string.upper(response) == "SWORD" then
                output.Text = "Great choice! I knew you would pick the sword!"
                tools.Sword:Clone().Parent = player.Backpack
                break
           end
      end
end
0
An error occurs and it says, "09:03:46.279 - Players.Player1.PlayerGui.ScreenGui.LocalScript:35: attempt to index global 'player' (a nil value)". caelyn1567 10 — 7y
0
Probably Fixed. Please paste it to LocalScript and it will probably work ;) Etheroit 178 — 7y
Ad

Answer this question