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

Insert a variable into an object?

Asked by 3 years ago

So In my Admin Panel GUI, I have a textbox where I type the player's name and click the "teleport to" button. However, I'm using a UI library. So I can make the variable whatever I want. I made it "text". The code for the button looks like this:

game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = game.Players.text.Character.HumanoidRootPart.CFrame

But, the problem is that the game thinks that I'm to teleport to a player named "text", and of course there's no player named text. Is there a way I could insert the variable into the object?

section1:addTextbox("Player:", "Username Here", function(text, focusLost)
    print("Input", text)

    if focusLost then
        venyx:Notify("Player", text)
    end
end)

section1:addButton("Fastkill")
section1:addButton("Kill")
section1:addButton("Bring")
section1:addButton("Fastbring")
section1:addButton("Teleport To", function()
    game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = game.Players.text.Character.HumanoidRootPart.CFrame
end)

(Section1 refering to a section in the gui.) (Lost focus referring to when the user loses focus of the textbox.)

2 answers

Log in to vote
0
Answered by
iHavoc101 127
3 years ago

You are using a UI framework.

Every UI framework is different.

I think the answer should be:

local TargetPlayer = nil

local function GetPlayerFromString(String)
    local msg = String:lower()
    for _, v in pairs(game.Players:GetPlayers()) do
        local name = v.Name:lower():sub(0, msg:len())
        if name == msg then
            return v
        end
    end
    return nil
end

section1:addTextbox("Player:", "Username Here", function(text, focusLost)
    print("Input" .. text)
   TargetPlayer = text

    if focusLost then
        venyx:Notify("Player", text)
    end
end)

section1:addButton("Fastkill")
section1:addButton("Kill")
section1:addButton("Bring")
section1:addButton("Fastbring")
section1:addButton("Teleport To", function()
    game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = GetPlayerFromString(TargetPlayer).Character.HumanoidRootPart.CFrame
end)

Try not to ask for help on exploits too often, okay?

0
Helps thanks! Also, I don't intend to cause harm. I mostly pen test my games. ScriptedWrath 16 — 3y
Ad
Log in to vote
0
Answered by
Leamir 3138 Moderation Voter Community Moderator
3 years ago

You can use [Variable] to insert a variable in that case:

section1:addTextbox("Player:", "Username Here", function(text, focusLost)
    print("Input", text)

    if focusLost then
        venyx:Notify("Player", text)
    end
end)

section1:addButton("Fastkill")
section1:addButton("Kill")
section1:addButton("Bring")
section1:addButton("Fastbring")
section1:addButton("Teleport To", function()
    game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = game.Players[text].Character.HumanoidRootPart.CFrame
end)
0
When I try that the teleport too button doesn't click or do anything. ScriptedWrath 16 — 3y

Answer this question