So I was working on a trolling gui for a game of mine and if you typed someone's username it would keep loop tping to them, but how would i check if that name was in players. and how would I add the name to the script, and with loop tping to them if you touched them they would get flinged which is another script i found online.
togglebutton = script.Parent.Parent.TextButton players= game.Players:GetChildren() toggle = script.Parent.Parent.Toggle repeat wait(0.1) until script.Parent.Text == players.Name local player = script.Parent.Text while toggle.Value == true do wait(0.1) game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = game.Players(player).Character.HumanoidRootPart.CFrame end togglebutton.MouseButton1Click:Connect(function() toggle.Value = not toggle.Value end)
You can use GetPropertyChangedSignal to run a function every time a textbox's text changes: The script will check if that player's name is inside game.Players.
One way we could check if the text is a player's name is by doing game.Players:FindFirstChild(script.Parent.Text)
, but this is case sensitive and we probably don't want that.
How we'd make it not case sensitive is by going through the players and looking to see if the players name in lower case is the same as the text inputed in lower case:
function searchForPlayer(playerName) for _, player in pairs(game.Players:GetPlayers())do if string.lower(player.Name) == string.lower(playerName) then return player end end -- if we get here, we went thru all the players in game.Players and non of their names were playerName so the script will return nil end script.Parent:GetPropertyChangedSignal("Text"):Connect(function() --look inside game.Players to see if the text is a players name. --this is NOT case sensitive local player = searchForPlayer(playerName) if player then --a player's name was typed into the textbox, --TODO: this is where you'd write the code to teleport your player end end)