1 | game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect( function (player,Text) |
2 | print (Text) |
3 |
4 | end ) |
Is it possible to add a line of code like this game.Players.[I want to use the variable here]
You can do this by adding brackets []
at the end of an object, like this:
1 | local player = "Player123" |
2 | game.Players [ player ] :Kick( "Example" ) |
This can be useful for manipulating string like this:
1 | -- Assuming there's a player called Player123 and yer123 |
2 | local player = game.Players.Player 123 |
3 | local bot = string.sub(player.Name, 4 ) -- should be 'yer123' |
4 | if not player:FindFirstChild(bot) then return end |
5 | game.Players [ bot ] :Kick( "Example" ) |