–Story--------------------------------------------------------------------
So, I making a parkour game, and I need help with a Gui, so i have made all of the parkour courses and everything, so i got an idea of like a trolling kind of gui which would troll another player, like killing them or teleporting them
–I need Help With------------------------------------------------------
so i made a gui and i need help, like when a player puts another player’s name and hits the “TP!” button,
i want to make it so that it should teleport the requested player to the player who clicked the tp button
I tried to make it on my own but i wasnt able to.
Also I am not that good of a scripter.
Any Help Would be great for me.
local Textbox -- where you input Player's name
local Button -- the teleport button
local Selected -- Selected Player
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local PrimaryPart = Character.PrimaryPart
Textbox.FocusLost:Connect(function()
local Text = string.lower(Textbox.Text)
for i, v in pairs(Players:GetChildren()) do
if string.lower(v.Name) == Text then
Textbox.Text = v.Name
Selected = v
end
end
end)
Button.MouseButton1Click:Connect(function()
if PrimaryPart and Selected then
Selected.Character.PrimaryPart.Position = PrimaryPart.Position
end
end)
--[[ this should be done on server because the player's character wont teleport
-- Client --
Button.MouseButton1Click:Connect(function()
if PrimaryPart and Selected then
RemoteEvent:FireServer(Selected.Name, PrimaryPart.Position)
end
end)
-- Server --
RemoteEvent.OnServerEvent:Connect(function(Player, Name, Position)
if Players:FindFirstChild(Name) and Players[Name].Character then
Players[Name].Character.PrimaryPart.Position = Position
end
end)
--]]
local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local RemoteEvent = RS:WaitForChild("TeleportPlayer")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local PrimaryPart = Character:WaitForChild("HumanoidRootPart")
---------------------------------------------------------
local Textbox
local Button
---------------------------------------------------------
local Selected
Textbox.FocusLost:Connect(function()
local Text = string.lower(Textbox.Text)
for i, v in pairs(Players:GetChildren()) do
if string.lower(v.Name) == Text then
Textbox.Text = v.Name
Selected = v
break
end
end
end)
Button.MouseButton1Click:Connect(function()
if PrimaryPart and Selected then
RemoteEvent:FireServer(Selected.Name, PrimaryPart.Position)
end
end)
ServerScript
local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local RemoteEvent = RS:WaitForChild("TeleportPlayer")
RemoteEvent.OnServerEvent:Connect(function(Player, Name, Position)
if Players:FindFirstChild(Name) and Players[Name].Character then
Players[Name].Character:MoveTo(Position)
end
end)
in case ladzec’s code doesn’t work (which it shouldnt) or you don’t understand it, ill rewrite it completely but its practically done the same way, ill only give you the teleport one since you only asked for that one and also i want you to make the kill one yourself
client
local player = game.Players.LocalPlayer
local pgui = player.PlayerGui
local textbox = pgui:WaitForChild("ScreenGui").TextBox
local button = pgui:WaitForChild("ScreenGui").button
local event = game.ReplicatedStorage.tp
-- set all of the above to the path of your own stuff
local de = false -- delay for the teleport
local detime = .5 -- delay time, you can set this to whatever you want
local detect = false -- detect if player didnt press enter to enter in the name
local savedtext = "" -- name given
local otherplayername = "" -- variable for... i think you can guess
function focused()
if detect == true then
textbox.Text = savedtext -- saving their text
end
end
function focuslost(bool)
if bool == false then
savedtext = textbox.Text
detect = true
otherplayername = textbox.Text
return end
-- if they did press enter
detect = false
otherplayername = textbox.Text
end
function onclick()
if de == true then
textbox.Text = "please wait"
wait(.1)
textbox.Text = savedtext
return end
local otherplayer = game.Players:FindFirstChild(otherplayername)
if otherplayer == nil then -- if the player doesnt exist then
textbox.Text = "could not find the player"
de = true
wait(detime)
de = false
return end
if otherplayername == player.Name then
textbox.Text = "why are you trying to teleport to yourself?" -- incase
de = true
wait(detime)
de = false
return end
-- if you want this to be limited to only friends
-- if not player:IsFriendsWith(otherplayer.UserID) then
-- textbox.Text = "you are not friends with this person"
-- de = true
-- wait(detime)
-- de = false
-- return end
event:FireServer(otherplayer)
de = true
wait(detime)
de = false
end
textbox.FocusLost:Connect(focuslost)
textbox.Focused:Connect(focused)
button.MouseButton1Click:Connect(onclick)
this version also lets you only do it to friends if you want to do that
obviously i cant test the friends thing but you can if you want to
server
local event = game.ReplicatedStorage.tp
event.OnServerEvent:Connect(function(player, otherplayer)
local character = player.Character
local humanoidrootpart = character:FindFirstChild("HumanoidRootPart")
local otherplayercharacter = otherplayer.Character or otherplayer.CharacterAddded:Wait()
local otherrootpart = otherplayercharacter:FindFirstChild("HumanoidRootPart")
humanoidrootpart.Position = otherrootpart.Position
end)