Roblox teleport player not working

Well you said:

if script.Parent.plr1 == true and script.Parent.plr2 == true 

but aren’t those bool values? So you need to say:

if script.Parent.plr1.Value == true and script.Parent.plr2 .Value== true then
1 Like

here is the whole script

for the brick part 1

wait(1)
local e = game.Workspace.arena.Sever.plr1 
local s = e.Parent.Value1
script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") ~= nil then
		e.Value = true
		s.Value = hit.Parent.Name
		e.Parent.SurfaceGui.Frame.TextLabel.Text = hit.Parent.Name

	end
end)

script.Parent.TouchEnded:Connect(function()
	s.Value = tostring(nil)
	e.Value = false
	e.Parent.SurfaceGui.Frame.TextLabel.Text = "none"

end)

for the brick part 2

wait(1)
local e = game.Workspace.arena.Sever.plr2
local s = e.Parent.Value2
script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") ~= nil then
		e.Value = true
		s.Value = hit.Parent.Name
		e.Parent.SurfaceGui.Fram2e.TextLabel.Text = hit.Parent.Name

	end
end)

script.Parent.TouchEnded:Connect(function()
	s.Value = tostring(nil)
	e.Value = false
	e.Parent.SurfaceGui.Fram2e.TextLabel.Text = "none"

end)

and the final brick part it has all its boolean inside which script is to calculate if both player are standing on a brick

local l = script.Parent.Value1.Value

local s = script.Parent.Value2.Value


if script.Parent.plr1.Value and script.Parent.plr2.Value then
		print(tostring(l))
		print(tostring(s))
		game.Workspace:FindFirstChild(tostring(l)):SetPrimaryPartCFrame(CFrame.new(49.05, 1.5, -110.59)) 

	game.Workspace:FindFirstChild(tostring(s)):SetPrimaryPartCFrame(CFrame.new(8.42, 1.5, -103.83))

end

i am using print to check if its work

Try this:

local l = script.Parent.Value1.Value -- if the player touch the part a bool value will be its name(as a string) and  if the touch ended it will be nil (as a string) etc

local s = script.Parent.Value2.Value --same function applied here (dont mind about the variable names)

if script.Parent.plr1.Value == true and script.Parent.plr2.Value == true then --- when the player touch the part it actually set a bool value to true so if both player are touching the part both bool value will be set true then it will teleport them
print("trying to teleport!!")
wait(0.1)

game.Workspace:FindFirstChild(l).HumanoidRootPart.CFrame = CFrame.new(49.05, 1.5, -110.59) -- this is not working

game.Workspace:FindFirstChild(s).HumanoidRootPart.CFrame = CFrame.new(8.42, 1.5, -103.83) --this too

end

the script still not working :confused:

Did it print “trying to teleport”

Wait a sec, I was looking at your script and it’s not working because it will only run once in the beginning. You need to put that in a function that fires when the parts are touched.

nope it didnt print anything its very overheating my head rn

just use objectvalues instead of stringvalues for that. this way you can use ObjectValue.Value:SetPrimaryPartCFrame()
Because the values already references that object.
Also, because the .touched event only see what part is touching it, the parent of the part that touched it might not always be the player.

hmm can u give me an example if u can pls?

The problem here is that your code at the end only runs once, you tell it to check if the values are not nil, but because it is not in a function it only fires once and then is done. Is this code in a different script as the other code?

no its only on a part and ill try making it as a function

What part is it on. Is it the part that they step on to teleport?

wait(1)
local e = game.Workspace.arena.Sever.plr2
local s = e.Parent.Value2
script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") ~= nil then
		e.Value = true
		s.Value = hit.Parent
		e.Parent.SurfaceGui.Fram2e.TextLabel.Text = hit.Parent.Name

	end
end)

script.Parent.TouchEnded:Connect(function()
	s.Value = nil
	e.Value = false
	e.Parent.SurfaceGui.Fram2e.TextLabel.Text = "none"
end)
--------------------------------
local l = script.Parent.Value1.Value

local s = script.Parent.Value2.Value


if script.Parent.plr1.Value and script.Parent.plr2.Value then
		print(l.Name)
		print(s.Name)
		l:SetPrimaryPartCFrame(CFrame.new(49.05, 1.5, -110.59)) 

	s:SetPrimaryPartCFrame(CFrame.new(8.42, 1.5, -103.83))

end

Also, name your stuff properly. noone wants to debug variables A,B and C.

its on a part that has all the bool values

hmm that mean i should have the string value too also its still not working

1 Like

I would recommend moving that code to one of the other script. Then use a .Touched event to run the teleport code whenever it touches it.

but how can we use touch for both player i mean like can it detect the first player touching and the second one touching at the same time?

i get you’re trying to help, but please think of what the code would otherwise do. moving it to another script and referencing everything correctly after that won’t fix anything. a part in the workspace with a script in it can be refereneced by doing script.Parent and game.Workspace.Part .
Code in one script is the same as in another exept if it moves to or from the client.

It doesn’t need to check for both. When one player steps on one pad it will run that code and check if both pads have player’s on them.

1 Like

like how can it check that (sorry for being idiot i am very tired)

Try this in the script that checks when the second pad is hit:

wait(1)
local boolval = game.Workspace.arena.Sever.plr1 
local playervalue = e.Parent.Value1
local e  = game.Workspace.arena.Server.plr1
local s = e.Parent.Value1
script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") ~= nil then
		boolvalue.Value = true
		playervalue.Value = hit.Parent.Name
		e.Parent.SurfaceGui.Frame.TextLabel.Text = hit.Parent.Name
                print("touched by player")
                if boolval.Value == true and e.Value == true then
                     print("Teleporting")
                     print(playervalue.Value)
                     print(s.Value)
                    game.Workspace:FindFirstChild(playervalue.Value):SetPrimaryPartCFrame(CFrame.new(49.05, 1.5, -110.59)) 
	                 game.Workspace:FindFirstChild(s.Value):SetPrimaryPartCFrame(CFrame.new(8.42, 1.5, -103.83))

                end
	end
end)

script.Parent.TouchEnded:Connect(function()
	s.Value = tostring(nil)
	e.Value = false
	e.Parent.SurfaceGui.Frame.TextLabel.Text = "none"

end)