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

How do I make this GUI handle a tool to a specified player in-game?

Asked by 8 years ago

In this GUI you input the player's name on a TextBox and when you click on a TextButton it should give the player inputted in the TextBox an economy ticket.

This is the script inside the TextButton

function o()
    local text = "game.Players."..script.Parent.Parent.UsernameBox.Text
    print(text.Name)
    local plr = text
    script.Economy:Clone().Parent = plr.Backpack
end

script.Parent.MouseButton1Click:Connect(o)

It does call the function, I just don't know how to make it find the player I want. Please help me!

1 answer

Log in to vote
3
Answered by 8 years ago
Edited 8 years ago

Hey, I noticed your problem immediately. It's on line 4.

local plr = text

You set the variable 'plr' to a string ("game.Players.TEXT"). That doesn't actually locate the player here's your script fixed:

function o()
    local text = game.Players:FindFirstChild(script.Parent.Parent.UsernameBox.Text) -- This checks inside of game.Players for the playername that was entered. It's not a string, and the variable is a player object variable.
    print(text.Name)
    local plr = text
    script.Economy:Clone().Parent = plr.Backpack
end

script.Parent.MouseButton1Click:Connect(o)

Hope this helps and if it does be sure to accept it as the answer :)

0
Thanks! iDelta_Dev 2 — 8y
Ad

Answer this question