Teleport Part Not Working

Hello! I’m having some trouble with a script I wrote. Here is the section of the script that is not working:

This is a random room generation ModuleScript. Basically, I want there to be a chance that when you walk through to the next room, it teleports the player who touched ‘overEntrance’ to a different place where they will play a challenge. This isn’t working as intended and as of writing this part of the ModuleScript, my game has been getting EXTREMELY LAGGY upon playing the game. I am also getting

this error

in my output…

I would be extremely grateful if anyone found out what’s going wrong and can help me fix this. :slight_smile:

You need to check if the player exists.

overEntrance.Touched:Connect(function(hit)
    local player = Players:GetPlayerFromCharacter(hit.Parent)
    
    if player then
        player.Character.PrimaryPart.CFrame = workspace.TPto.CFrame
    end
end)
2 Likes

Thanks, it’s not erroring anymore, but it’s still not teleporting me. not sure if it’s something to do with the part, or…

1 Like

Does the teleport part ever actually get moved to where it’s supposed to be?

1 Like

I don’t see it there when I playtest.

Make sure to set it’s position of the part then.

Also, make sure the part is anchored.

1 Like

The script to open doors doesn’t detect if it’s a player or not so the part is opening the door. I have so many doors so it will take years to fix that. Is there a way around this?

Edit: can this even detect parts anyway?

Create a class or module for the door script, and then have the script in your doors load up the function within the module.

This way, you only have to update the module or class rather than each door when you make changes.

For example, a while back I was tasked with making a lot of seeSaws for a park. Rather than put all the code in each individual seesaw and just paste the code I created a seesaw class.

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SeeSaw = require(ReplicatedStorage.SeeSaw)
local currentSeeSaw = script.Parent
local LeftSeat = currentSeeSaw["Meshes/여러가지_Swing_Balancer_Plank"].LeftSeat
local RightSeat = currentSeeSaw["Meshes/여러가지_Swing_Balancer_Plank"].RightSeat

-- Load SeeSaw Class from Replicated Storage
mySeeSaw1 = SeeSaw.new(script.Parent)

local function moveSeeSaw(player)
mySeeSaw1:moveSeeSaw(player)
end

LeftSeat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if LeftSeat.Occupant then
		local character = LeftSeat.Occupant.Parent	
		local player = Players:GetPlayerFromCharacter(character)
		moveSeeSaw(player)	
	end
end)
RightSeat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if RightSeat.Occupant then
		local character = RightSeat.Occupant.Parent
		local player = Players:GetPlayerFromCharacter(character)
		moveSeeSaw(player)
	end
end)

and my class:

-- SeeSaw Class

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local QuestReward = require(ReplicatedStorage.QuestReward)
local QuestFolder = ReplicatedStorage.Quests
--local SeeSawQuest = QuestFolder.see

local SeeSaw = {}
SeeSaw.__index = SeeSaw

function SeeSaw.new(seeSawModel:Model)

	local self = {}
	setmetatable(self, SeeSaw)
	self.gameSeeSaw = seeSawModel
	self.seeSawBoard = self.gameSeeSaw:WaitForChild("Meshes/여러가지_Swing_Balancer_Plank")
	self.seeSawLeftSeat = self.seeSawBoard.LeftSeat
	self.seeSawRightSeat = self.seeSawBoard.RightSeat
	self.seeSawIsOn = self.gameSeeSaw.IsOn.Value
	self.direction = 1
	self.incr = 2
	self.deg = 0
	self.playerQuest = nil


	return self
end

function SeeSaw:getModelName()
	return self.gameSeeSaw
end

function SeeSaw:QuestCompleted()
	return self.playerQuest	
end

function SeeSaw:moveSeeSaw(player)
	print(player)
	local playerQuests = player:WaitForChild("Player Quests")
	local seeSawQuest = playerQuests:FindFirstChild("Ride SeeSaw")
	self.playerQuest = seeSawQuest.Completed.Value
	if SeeSaw:QuestCompleted() then
		print("Quest already completed")
	else
		print("Complete quest: Give player reward")
		QuestReward:updateQuest(player, true, "Ride SeeSaw")
	end
	while self.seeSawLeftSeat.Occupant or self.seeSawRightSeat.Occupant do
		local forwardStop = 7
		local backwardStop = -7
		self.deg += self.incr * self.direction

		self.gameSeeSaw.PrimaryPart.CFrame = self.gameSeeSaw:GetPrimaryPartCFrame() * CFrame.Angles(math.rad(self.deg), 0, 0)

		if self.deg > forwardStop then self.direction = -1 end
		if self.deg < backwardStop then self.direction = 1 end 
		task.wait(.2)
	end
end

return SeeSaw

So, if there is ever a problem with my seeSaw’s I just update the class and all the seesaws in the game will be automatically updated since they use my class.

As for the other question, detecting if a player is opening your door is possible. Typically you look for the hit. Parent and then check if that Parent is a Humanoid.

1 Like