Need Help With Scripting!

–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

– Gui -------------------------------------------------

Gui

–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.

Thanks For Reading,
The Spikey Man

1 Like
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)
--]]
2 Likes

what do i put for selected player’s character??? @V_ladzec

1 Like

its empty variable that will have player stored later in script there is no need to give it any value

1 Like

so i just have to make a server script and place it in gui? and put the code???
@V_ladzec

1 Like

Add remote event to ReplicatedStorage and script to ServerScriptService read my comments and if you understand what that means put everything in place


Exploerer
like this???
@V_ladzec

1 Like

yes but read comments under the script

the comments at the end say that this should be done on server wut that mean???
@V_ladzec

1 Like

the comments in the end say what should be done on the server and client

this should be easier to read

LocalScript
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)
1 Like

Where do i put the local script? and the server script should i just put it into the Tpscript in serverscriptservice???
@V_ladzec

ServerScript in ServerScriptService
LocalScript inside your GUI
RemoteEvent in ReplicatedStorage

1 Like

ScreenShot
Like This??? @V_ladzec

1 Like

yes if this doesnt work read the code above again because i edited it some
this is how it works

ok lemme check if this works afterwards

1 Like

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)
1 Like

the first one doesnt work becuase i had written it really quick and havent checked afterwards
see the one below it works