Hello! I am trying to make a teleport script for my game but it seems to not be working. I also am not getting any errors which is weird. Help needed.
local num = math.random(1, 5)
local TPad1 = game.Workspace.Pad2
local TPad2 = game.Workspace.Pad3
local TPad3 = game.Workspace.Pad4
local TPad4 = game.Workspace.Pad5
local TPad5 = game.Workspace.Pad6
if num = 1 then
script.Parent.Touched:Connect(function(touchPart)
if touchPart and touchPart.Parent and touchPart.Parent.Humanoid and touchPart.Parent.currentlyTeleporting.Value == false then
local Character = touchPart.Parent
local teleportLocation = CFrame.new(TPad1.CFrame.X, TPad1.CFrame.Y + 5, TPad1.CFrame.Z)
Character:SetPrimaryPartCFrame(teleportLocation)
local teleportingValue = Character.currentlyTeleporting
teleportingValue.Value = true
wait(3)
teleportingValue.Value = false
end
end)
if num = 2 then
script.Parent.Touched:Connect(function(touchPart)
if touchPart and touchPart.Parent and touchPart.Parent.Humanoid and touchPart.Parent.currentlyTeleporting.Value == false then
local Character = touchPart.Parent
local teleportLocation = CFrame.new(TPad2.CFrame.X, TPad2.CFrame.Y + 5, TPad2.CFrame.Z)
Character:SetPrimaryPartCFrame(teleportLocation)
local teleportingValue = Character.currentlyTeleporting
teleportingValue.Value = true
wait(3)
teleportingValue.Value = false
end
(end
if num = 3 then
script.Parent.Touched:Connect(function(touchPart)
if touchPart and touchPart.Parent and touchPart.Parent.Humanoid and touchPart.Parent.currentlyTeleporting.Value == false then
local Character = touchPart.Parent
local teleportLocation = CFrame.new(TPad3.CFrame.X, TPad3.CFrame.Y + 5, TPad3.CFrame.Z)
Character:SetPrimaryPartCFrame(teleportLocation)
local teleportingValue = Character.currentlyTeleporting
teleportingValue.Value = true
wait(3)
teleportingValue.Value = false
end
(end
if num = 4 then
script.Parent.Touched:Connect(function(touchPart)
if touchPart and touchPart.Parent and touchPart.Parent.Humanoid and touchPart.Parent.currentlyTeleporting.Value == false then
local Character = touchPart.Parent
local teleportLocation = CFrame.new(TPad4.CFrame.X, TPad4.CFrame.Y + 5, TPad4.CFrame.Z)
Character:SetPrimaryPartCFrame(teleportLocation)
local teleportingValue = Character.currentlyTeleporting
teleportingValue.Value = true
wait(3)
teleportingValue.Value = false
end
(end
if num = 5 then
script.Parent.Touched:Connect(function(touchPart)
if touchPart and touchPart.Parent and touchPart.Parent.Humanoid and touchPart.Parent.currentlyTeleporting.Value == false then
local Character = touchPart.Parent
local teleportLocation = CFrame.new(TPad5.CFrame.X, TPad5.CFrame.Y + 5, TPad5.CFrame.Z)
Character:SetPrimaryPartCFrame(teleportLocation)
local teleportingValue = Character.currentlyTeleporting
teleportingValue.Value = true
wait(3)
teleportingValue.Value = false
end
(end
local num = math.random(1, 5)
local TPad1 = game.Workspace.Pad2
local TPad2 = game.Workspace.Pad3
local TPad3 = game.Workspace.Pad4
local TPad4 = game.Workspace.Pad5
local TPad5 = game.Workspace.Pad6
if num == 1 then
script.Parent.Touched:Connect(function(touchPart)
if touchPart and touchPart.Parent and touchPart.Parent.Humanoid and touchPart.Parent.currentlyTeleporting.Value == false then
local Character = touchPart.Parent
local teleportLocation = CFrame.new(TPad1.CFrame.X, TPad1.CFrame.Y + 5, TPad1.CFrame.Z)
Character:SetPrimaryPartCFrame(teleportLocation)
local teleportingValue = Character.currentlyTeleporting
teleportingValue.Value = true
wait(3)
teleportingValue.Value = false
end
end)
if num = 2 then
script.Parent.Touched:Connect(function(touchPart)
if touchPart and touchPart.Parent and touchPart.Parent.Humanoid and touchPart.Parent.currentlyTeleporting.Value == false then
local Character = touchPart.Parent
local teleportLocation = CFrame.new(TPad2.CFrame.X, TPad2.CFrame.Y + 5, TPad2.CFrame.Z)
Character:SetPrimaryPartCFrame(teleportLocation)
local teleportingValue = Character.currentlyTeleporting
teleportingValue.Value = true
wait(3)
teleportingValue.Value = false
end
end)
elseif num == 3 then
script.Parent.Touched:Connect(function(touchPart)
if touchPart and touchPart.Parent and touchPart.Parent.Humanoid and touchPart.Parent.currentlyTeleporting.Value == false then
local Character = touchPart.Parent
local teleportLocation = CFrame.new(TPad3.CFrame.X, TPad3.CFrame.Y + 5, TPad3.CFrame.Z)
Character:SetPrimaryPartCFrame(teleportLocation)
local teleportingValue = Character.currentlyTeleporting
teleportingValue.Value = true
wait(3)
teleportingValue.Value = false
end
end)
elseif num == 4 then
script.Parent.Touched:Connect(function(touchPart)
if touchPart and touchPart.Parent and touchPart.Parent.Humanoid and touchPart.Parent.currentlyTeleporting.Value == false then
local Character = touchPart.Parent
local teleportLocation = CFrame.new(TPad4.CFrame.X, TPad4.CFrame.Y + 5, TPad4.CFrame.Z)
Character:SetPrimaryPartCFrame(teleportLocation)
local teleportingValue = Character.currentlyTeleporting
teleportingValue.Value = true
wait(3)
teleportingValue.Value = false
end
end)
elseif num == 5 then
script.Parent.Touched:Connect(function(touchPart)
if touchPart and touchPart.Parent and touchPart.Parent.Humanoid and touchPart.Parent.currentlyTeleporting.Value == false then
local Character = touchPart.Parent
local teleportLocation = CFrame.new(TPad5.CFrame.X, TPad5.CFrame.Y + 5, TPad5.CFrame.Z)
Character:SetPrimaryPartCFrame(teleportLocation)
local teleportingValue = Character.currentlyTeleporting
teleportingValue.Value = true
wait(3)
teleportingValue.Value = false
end
end)
Touched:Connect(function()
if something1 then
something1
elseif something2 then
something2
end
end)
Not:
if stuff1 then
Touched:Connect(function()
if things then
doStuff
end
end)
elseif stuff2 then
Touched:Connect(function()
if things then
doStuff
end
end)
This is formatted horribly because I’m on phone (I realised it became worse out of edit mode)
I would recommend adding tons of prints to find the exact place where the code breaks. You have a lot of if statements so one of them probably isn’t firing when you want them too.
Here you do, I’m not sure if it will work, but let’s hope. Your code is too big, and can be simplified easily. Let me know if you have any more issues!
local num
-- Line of code that actually teleports the player.
local function Teleport(touchPart)
local teleportpart = "Pad"..num
print(teleportpart)
local teleportpath = game.Workspace[teleportpart]
local teleportLocation = CFrame.new(teleportpath.CFrame.X, teleportpath.CFrame.Y + 5, teleportpath.CFrame.Z)
local char = touchPart.Parent
local teleportingValue = char.currentlyTeleporting
char:SetPrimaryPartCFrame(teleportLocation)
teleportingValue.Value = true
wait(3)
teleportingValue.Value = false
end
-- Checks and randomizes the teleport.
local function randomizenumber(touchPart)
local num = math.random(1, 5) -- Define what the maximum and minimum teleports are!
if touchPart and touchPart.Parent and touchPart.Parent.Humanoid and touchPart.Parent.currentlyTeleporting.Value == false then
Teleport(touchPart) -- Run the function.
end
end
script.Parent.Touched:Connect(randomizenumber)