Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make a variable work in a path?

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.

1 comment

0

Error:script:2:Unknown global "username".

2 answers

players[username]:Kick()

instead of

players.username:Kick()

Im retarded...

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

1 comment

0

:kick is deprecated, use :Kick, :connect is deprecated, use :Connect

This discussion is preserved as it was. New answers, comments, and votes are closed.