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

My button wont find the input of my textbox?

Asked by 4 years ago

Ok so basicly im trying to make it so when I click a button it checks the text in a textbox then searches that inside my players backpack and clones the tool with the text in the text box. ex. TextBox text says "BasicAxe" then I click the button and it looks for something called that in my player backpack and clones it so I have two.

If you need more info on what stuff is or looks like i'll respond with the info.

1 answer

Log in to vote
0
Answered by 4 years ago

To do this via a local GUI, you must use the server so that you have the tool for all clients/server.

You will need a localscript, RemoteEvent in replicatedStorage, and a script in serverScriptService.

The localscript should look like this:

local textbox = script.Parent.Parent.TextBox -- Location of textbox


script.Parent.MouseButton1Click:connect(function() --On click
    local toolName = textbox.Text --Takes string of text box
    game.ReplicatedStorage.cloneGear:FireServer(toolName) -- Fire event called "cloneGear"
end)

This is the server side script

game.ReplicatedStorage.cloneGear.OnServerEvent:Connect(function(plr, toolName)
    local tool = plr.Backpack:FindFirstChild(toolName)
    if tool ~= nil then
        local newTool = tool:Clone()
        newTool.Parent = plr.Backpack
    end

end)

To change it to search in server storage, change the 2nd line of server side, changing it to

|Location|:FindFirstChild(toolName).

Hope this helps :)

0
Where does the localscript go? I didnt pick that up. RowanStrohmYT 2 — 4y
0
nvm RowanStrohmYT 2 — 4y
Ad

Answer this question