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

Is it possible to use a variable in an explorer pathway?

Asked by 5 years ago
1game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player,Text)
2    print(Text)
3 
4end)

Is it possible to add a line of code like this game.Players.[I want to use the variable here]

1 answer

Log in to vote
0
Answered by 5 years ago

You can do this by adding brackets [] at the end of an object, like this:

1local player = "Player123"
2game.Players[player]:Kick("Example")

This can be useful for manipulating string like this:

1-- Assuming there's a player called Player123 and yer123
2local player = game.Players.Player123
3local bot = string.sub(player.Name, 4) -- should be 'yer123'
4if not player:FindFirstChild(bot) then return end
5game.Players[bot]:Kick("Example")
Ad

Answer this question