SetPrimaryPartCFrame issue - or, im not sure really

So, the main goal for whatever I’m making, is to allow usage of a tool to keep track of points, and being able to teleport back to points you’ve made.

The issue I’ve found, after some testing, can be reproduced like this.
Use the tool normally on your first spawn. Works perfectly fine as intended.
HOWEVER! Once you reset with this tool, and try to create a new position point, the new point will not work as intended. (It will teleport you to the place you last teleported before you reset.)

So far, I’ve tried creating new cframes rather then telling the server the data, didn’t work. I tried not using a global module to save my positions (they’d lose all teleport points on reset) but that still didn’t work either. I’ve put plenty of prints, only real issue I’ve found is that the server doesn’t always get the EXACT cframe the client is sending, but even then the positions should still be the same.

Here’s the issue in action
https://gyazo.com/25a1f48ee86b591272444d89f00acd80.mp4
As you can see, in this video, the button does NOT teleport me correctly

Here’s the output for the same gif.
https://gyazo.com/619dc682af55569c793a2d3aa0270b50.png

CLIENT teleportation & position saving handler

UIS.InputBegan:Connect(function(Key,Registered)
	if Registered == false and Key.UserInputType == Enum.UserInputType.Keyboard and Equipped == true and Key.KeyCode == Enum.KeyCode.R and ReturnName.Parent == script then
		
		ReturnName.Parent = Player.PlayerGui
		
		ReturnName.Enter.Activated:Wait()
		
		CurrentPoints[ReturnName.TextBox.Text] = Character.Torso.CFrame
		
		print("setting ".. ReturnName.TextBox.Text .." to ".. tostring(CurrentPoints[ReturnName.TextBox.Text]) ..", char is @ ".. tostring(Character.Torso.CFrame))
		
		ReturnName.Parent = script
		ReturnName.TextBox.Text = ""
	end
end)

Tool.Activated:Connect(function()
	if Equipped == true and List.Parent == script then
		List.Parent = Player.PlayerGui
		
		local Example = List.ScrollingFrame.Example
		Example.Parent = script
		
		local Offset = 0
		local HasBeenPressed = false
		local PressedButton = nil
		
		for Name, CF in pairs(CurrentPoints) do
			local Button = Example:Clone()
			
			Button.Text = Name
			
			Button.Position = UDim2.new(0,0,0,Offset)
			
			List.ScrollingFrame.CanvasSize = UDim2.new(0,0,0,Offset)
			
			Offset = Offset + 50
			
			Button.Parent = List.ScrollingFrame
			
			Button.Activated:Connect(function()
				HasBeenPressed = true
				PressedButton = Button
			end)
		end
		
		repeat
			game:GetService("RunService").RenderStepped:Wait()
		until HasBeenPressed == true
		
		List.ScrollingFrame:ClearAllChildren()
		
		Example.Parent = List.ScrollingFrame
		
		List.Parent = script
		
		Tool.Communicate:FireServer("changepos", CurrentPoints[PressedButton.Text])
		
		print("teleporting to ".. PressedButton.Text .." pos which is at ".. tostring(CurrentPoints[PressedButton.Text]))
	end
end)

SERVER position handling

Tool.Communicate.OnServerEvent:Connect(function(Player, Type, CF)
	if Player == game.Players:GetPlayerFromCharacter(Tool.Parent) then
		if Type == "changepos" then
			print("recieved ".. tostring(CF))
			
			game.ReplicatedStorage.RenderVanish:FireAllClients(Tool.Parent)
			
			wait(.55)
			
			local Hitbox = Instance.new("FlagStand")
			
			Hitbox.CFrame = Player.Character.HumanoidRootPart.CFrame
			Hitbox.Transparency = 1
			Hitbox.Anchored = true
			Hitbox.CanCollide = false
			Hitbox.Size = Vector3.new(4, 5, 1)
			
			Hitbox.Parent = workspace
			
			local Touching = Hitbox:GetTouchingParts()
			
			for _, Part in pairs(Touching) do
				if Part.Parent:FindFirstChild("Humanoid") and not CAS:HasTag(Part.Parent,"TPING") and not Part:IsDescendantOf(Player.Character) then
					CAS:AddTag(Part.Parent,"TPING")
					
					Part.Parent:SetPrimaryPartCFrame((CF*CFrame.new(0,0,-5))*Player.Character.HumanoidRootPart.CFrame:toObjectSpace(Part.Parent.PrimaryPart.CFrame))
					
					coroutine.wrap(function()
						wait(.5)
						CAS:RemoveTag(Part.Parent,"TPING")
					end)()
				end
			end
			
			Hitbox:Destroy()
			
			Player.Character:SetPrimaryPartCFrame((CF*CFrame.new(0,0,-5)))
			print("teleported player to ".. tostring(CF))
		end
	end
end)

Yes, I do know this could easily be exploited to be used as a teleporter, but this is really only for me. That’s besides the point. I don’t understand WHY this issue would exist, considering all of the scripts that change and affect position are destroyed on respawn, and replaced with new ones.

Of course, if you happen to find any other issues please let me know.

Fixed it… Not really sure what the issue was still.

I redefined Character in each function. Doesn’t explain what the issue was, but whatever

1 Like