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

How do I make a variable work in a path?

Asked by 6 years ago
print("username located")
print(username)
local players = game.Players


function kick()
    print("Running function")
    local username = script.Parent.Parent.Userkicker.Text
    print("username located")
    print(username)
    print("kicking")
    players.username:kick()
    print("player kicked")
end


script.Parent.MouseButton1Click:connect(kick)
    players.username:kick()

gives an error stating: 14:18:43.100 - username is not a valid member of Players

I dont know how to make the variable work in a middle of a path.

0
Error:script:2:Unknown global "username". hiimgoodpack 2009 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago
players[username]:Kick()

instead of

players.username:Kick()

Im retarded...

Ad
Log in to vote
0
Answered by 6 years ago

Your problem is probably you spelled username incorrectly, do "Username".

Your script should look more like this with a few fixes;

print("Username located")
print(Username)
local players = game.Players


function kick()
    print("Running function")
    local Username = script.Parent.Parent.Userkicker.Text
    print("Username located")
    print(Username)
    print("kicking")
    players.Username:kick()
    print("player kicked")
end


script.Parent.MouseButton1Down:connect(kick)

If the script on top doesn't work then try this;

print("UserName located")
print(UserName)
local players = game.Players


function kick()
    print("Running function")
    local UserName = script.Parent.Parent.Userkicker.Text
    print("UserName located")
    print(UserName)
    print("kicking")
    players.UserName:kick()
    print("player kicked")
end


script.Parent.MouseButton1Down:connect(kick)

If worked make sure to accept answer :D

0
:kick is deprecated, use :Kick, :connect is deprecated, use :Connect hiimgoodpack 2009 — 6y

Answer this question