Advertisement
The_Newt

[ROBLOX] Lobby Teleport Pad Script

Oct 8th, 2014
1,927
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.60 KB | None | 0 0
  1. --[[
  2. updated 09-10-2014
  3. script for a lobby teleportation pad
  4. programmed by NewtPewt
  5. ]]--
  6.  
  7. game:getservice("teleportservice").customizedteleportgui = true
  8. ds = game:getservice("datastoreservice"):getglobaldatastore()
  9. local trigger = script.parent
  10. function debounce(func)
  11.     local isrunning = false
  12.     return function(...)
  13.         if not isrunning then
  14.             isrunning = true
  15.             func(...)
  16.             isrunning = false
  17.         end
  18.     end
  19. end
  20. function getplayer(part)
  21.     local humanoid = part.parent:findfirstchild("humanoid")
  22.     if (humanoid ~= nil) then
  23.         local character = humanoid.parent
  24.         if (character ~= nil) then
  25.             return game:getservice("players"):getplayerfromcharacter(character)
  26.         end
  27.     end
  28. end
  29. function _sendplayertobuildzone(player)
  30.     local playeridentity = player.name .. "(" .. player.userid .. ")"
  31.     local playerkey = "player_" .. player.userid
  32.     local playerdata = ds:getasync(playerkey)
  33.     if playerdata then
  34.         if playerdata.personalplaceid <= 0 then
  35.             playerdata = nil
  36.         end
  37.     end
  38.     if not playerdata then
  39.         newplaceid = game:getservice("assetservice"):createplaceasync("Building zone for " .. playerIdentity, 92697995)
  40.         playerdata = {
  41.             personalplaceid = newplaceid
  42.         }
  43.         ds:getasync(playerkey, playerdata)
  44.     end
  45.     if playerdata and playerdata.personalplaceid then
  46.         game:getservice("teleportservice"):teleport(playerdata.personalplaceid, player)
  47.     end
  48. end
  49. local sendplayertobuildzone = debounce(_sendplayertobuildzone)
  50. function ontouch(source)
  51.     local player = getplayer(source)
  52.     if player then
  53.         if player.userid > 0 then
  54.             sendplayertobuildzone(player)
  55.         end
  56.     end
  57. end
  58. trigger.touched:connect(ontouch)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement