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 4 years ago
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player,Text)
    print(Text)

end)

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 4 years ago

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

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

This can be useful for manipulating string like this:

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

Answer this question