Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --# Portal Teleportation
- --# Define Services
- local Players = game:GetService('Players')
- local RS = game:GetService('ReplicatedStorage')
- --# Define remote to tell client to fade in / fade out
- local fadeRemote = RS:WaitForChild('Fade')
- --# Define portals that are going to be used
- local portalA = workspace:WaitForChild('PortalA')
- local portalB = workspace:WaitForChild('PortalB')
- --# Hold players in table to ensure that one player cannot be teleported multiple times
- local playersBeingTeleported = {}
- --# If a player touches a portal, this will teleport them
- local function teleportCharacter(char, portal)
- --# Ensure that the character that touched the portal is in our Players list
- --# (basically verifiying that an NPC/zombie doesn't teleport)
- if Players:FindFirstChild(char.Name) then
- --# Tell the Client that touched to Fade Out
- fadeRemote:FireClient(Players[char.Name], 'Fade Out')
- wait(1)
- --# Move the Character that touched
- char.PrimaryPart.CFrame = CFrame.new(portal.MovePart.Position, portal.Exit.Position)
- --# Tell the Client that touched to Fade In
- fadeRemote:FireClient(Players[char.Name], 'Fade In')
- wait(0.2)
- --# Make it appear as if the player is running out of the portal
- char.Humanoid:MoveTo(portal.Exit.Position)
- --# Remove the player name from the table that is holding all of the players
- --# (this is because the teleportation effect has finished)
- wait(2)
- playersBeingTeleported[char.Name] = nil
- end
- end
- --# Handling the entering of portals #--
- --# If the main part of the portal is touched
- portalA:WaitForChild('MovePart').Touched:Connect(function(hit)
- --# Touched by a player (not an NPC/Zombie/etc.)
- if hit.Parent and hit.Parent:FindFirstChild('Humanoid') and Players:FindFirstChild(hit.Parent.Name) then
- --# Touched by an alive player
- if hit.Parent.Humanoid.Health > 0 then
- --# Add the players to the list of players being teleported
- if playersBeingTeleported[hit.Parent.Name] == nil then
- playersBeingTeleported[hit.Parent.Name] = 'teleporting...'
- --# Teleport the player
- teleportCharacter(hit.Parent, portalB) --# parameters are the Character to teleport, and the portal to goto
- end
- end
- end
- end)
- --# Handling portalB is almost the same except for a few differences
- --# Waiting for portalB to be touched (instead of portal A)
- portalB:WaitForChild('MovePart').Touched:Connect(function(hit)
- if hit.Parent and hit.Parent:FindFirstChild('Humanoid') then
- if hit.Parent.Humanoid.Health > 0 then
- if playersBeingTeleported[hit.Parent.Name] == nil then
- playersBeingTeleported[hit.Parent.Name] = 'teleporting...'
- teleportCharacter(hit.Parent, portalA) --# Going to portalA instead of portalB
- end
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement