The best way to prevent going on-top of a part


Situation

I’m currently making a jail command but when they reset/rejoin, I want them to teleport back into the cell.

Issue

Every time I try to get a character to re-teleport back into the cell, it goes on-top of it; instead of in.

Workarounds

None

Solutions Tried

  • I tried turning Can Collide off for the roof, to no avail,

I have no other ideas on how to fix this.


Script

	["In Jail Check"] = {
		Description = "",
		Function = function(plr)
			local Variables,Workspace = CommunicationModule.FindModule("Variables"),CommunicationModule.FindService("Workspace")
			if table.find(Variables.Tables.InJail,plr.Name) then
				if not Workspace:FindFirstChild(plr.Name.." Jail") then
					local ClonedJail =  script.Parent.Parent.Items.Jail:Clone()
					ClonedJail.Name = plr.Name.." Jail"
					ClonedJail.PrimaryPart.Position = Workspace[plr.Name].HumanoidRootPart.Position
					ClonedJail.Parent = Workspace
				else
					Players[plr.Name].Character:MoveTo(Workspace[plr.Name.." Jail"].Bottom.Position)
				end
			end
			return true
		end,

Thank you for any assistance you may give.

there’s an obscure feature that makes it so when a part’s position is changed to a position that makes it collide with different surfaces it’ll snap to a free spot to avoid collision, just use

Players[plr.Name].Character:SetPrimaryPartCFrame(Workspace[plr.Name.." Jail"].Bottom.CFrame)

instead as cframing isn’t affected by this

1 Like