Player not teleporting correctly

  1. What do you want to achieve?
    For the Player to teleport correctly to the tool holder’s HumanoidRootPart and not away from it.

  2. What is the issue?
    The Player being teleported is teleporting far from the tool holder’s HumanoidRootPart. It should be teleporting correctly because the HumanoidRootPart for the tool holder’s position is correct.

  3. What solutions have you tried so far?
    I tried using Model:MoveTo() But that didn’t fix it at all.

--This code does the teleporting
player.Character.HumanoidRootPart.Position = Vector3.new(FlagValuesFolder.FlagObject.Value.Parent.HumanoidRootPart.Position)
Full Code
local FlagModule = {}

function FlagModule.FlagEquipped(uselesstable, flag)
	local ReplicatedStorageService = game:GetService("ReplicatedStorage")
	local FindFlagValueFolder = ReplicatedStorageService.FlagValues:FindFirstChild(tostring(flag))
	local FindFlagEquippedValue
	local FindFlagObjectValue
	if FindFlagValueFolder then
		FindFlagEquippedValue = FindFlagValueFolder:FindFirstChild("Equipped")
		FindFlagObjectValue = FindFlagValueFolder:FindFirstChild("FlagObject")
		if FindFlagEquippedValue then
			FindFlagEquippedValue.Value = true
		else
			FindFlagEquippedValue = Instance.new("BoolValue", FindFlagValueFolder)
			FindFlagEquippedValue.Name = "Equipped"
			FindFlagEquippedValue.Value = true
		end
		
		if FindFlagObjectValue then
			FindFlagEquippedValue.Value = flag
		else
			FindFlagEquippedValue = Instance.new("ObjectValue", FindFlagValueFolder)
			FindFlagEquippedValue.Name = "FlagObject"
			FindFlagEquippedValue.Value = flag
		end
	else
		FindFlagValueFolder = Instance.new("Folder", ReplicatedStorageService.FlagValues)
		FindFlagValueFolder.Name = tostring(flag)
		if not FindFlagEquippedValue then
			FindFlagEquippedValue = Instance.new("BoolValue", FindFlagValueFolder)
			FindFlagEquippedValue.Name = "Equipped"
			FindFlagEquippedValue.Value = true
		end
		if not FindFlagObjectValue then
			FindFlagEquippedValue = Instance.new("ObjectValue", FindFlagValueFolder)
			FindFlagEquippedValue.Name = "FlagObject"
			FindFlagEquippedValue.Value = flag
		end
	end
end

function FlagModule.FlagUnequipped(uselesstable, flag)
	local ReplicatedStorageService = game:GetService("ReplicatedStorage")
	local FlagValuesFolder = ReplicatedStorageService:FindFirstChild(tostring(flag), true)
	FlagValuesFolder.Equipped.Value = false
end

function FlagModule.TeleportToFlag(uselesstable, flagname, player)
	local ReplicatedStorageService = game:GetService("ReplicatedStorage")
	local FlagValuesFolder = ReplicatedStorageService:FindFirstChild(tostring(flagname), true)
	if FlagValuesFolder then
		if FlagValuesFolder.Equipped.Value == true then
			player.Character.HumanoidRootPart.Position = Vector3.new(FlagValuesFolder.FlagObject.Value.Parent.HumanoidRootPart.Position)
		end
	end
end

return FlagModule

Also, I do not get any errors.

Here is a video of what happens:
robloxapp-20220405-0950398.wmv (1.7 MB)

I don’t think you need to add Vector3.new() - Try removing it and only let the HumanoidRootPart’s position.

You do. It needs a Vector3 Value and not a 3 number value.

Isn’t .Position already a Vector3 value though? The best thing i could also think about it is getting it’s CFrame instead.

Yeah CFrame might work.

It is but something to do with Position needs it to be reconverted to Vector3, I ran into this issue when I was learning and you do need to use Vector3.

1 Like

Yeah. Can’t use CFrame.

ServerScriptService.FlagModule:53: invalid argument #1 to ‘new’ (Vector3 expected, got CFrame) - Server - FlagModule:53

Correct me if i’m wrong, But CFrames also have a .Position value, I’m not sure if trying to convert/use it would be a great idea. Another thing you could do is use Model:SetPrimaryPartCFrame() instead of just changing the HumanoidRootPart’s CFrame/Position straight away.

local CFrameValue = CFrame.new(1, 2, 3)
local CFrameVector3 = CFrameValue.Position
print(CFrameVector3) -- 1, 2, 3
2 Likes

CFrame doesn’t have a Position Value, just the CFrame value is the value itself.

1 Like

Nevermind, This fixed it. Thanks.

1 Like