Portal script sometimes not teleporting on touched?
Hey, So I made a portal script and sometimes when the player touches the teleport part it doesn't teleport them to the designated area.
Heres my script:
03 | local Portals = game:GetService( "Workspace" ).PortalArea.Portals |
08 | function disconnectFunction(connection) |
10 | connection:disconnect() |
15 | for i,v in pairs (Portals:GetChildren()) do |
16 | connection = v.TouchPart.Touched:Connect( function (Hit) |
17 | if game.Players:FindFirstChild(Hit.Parent.Name) then |
18 | local Humanoid = Hit.Parent:FindFirstChild( "Humanoid" ) or Hit.Parent.Parent:FindFirstChild( "Humanoid" ) |
19 | if Humanoid.Health > 0 then |
20 | local Character = Humanoid.Parent |
21 | local HumanoidRootPart = Character.HumanoidRootPart |
22 | local Destination = v:FindFirstChild( "Destination" ).Value |
23 | local TeleportTo = Portals [ tostring (Destination) ] .TeleportPart.CFrame |
25 | HumanoidRootPart.CFrame = TeleportTo |
30 | disconnectFunction(connection) |