Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Detecting Speech, Location and UserId for teleportation?

Asked by 5 years ago

So I am making a teleport system for a few players in my game so that they can move around the map sufficiently. However, I want it so they must be touching a certain part called "Teleport1" which is located in game.Workspace.Teleports.Teleport1. However, the following script allows the players to teleport whenever they want regardless if they are touching a part or not because i'm unsure how to add the touch function into this code and then to register it when the player says the command.

local isAdmin = {[14946581] = true, [28433911] = true, [51013956] = true}

PC = script.Places.PotionClass
TC = script.Places.TransfigClass
Dor = script.Places.Dorm
Te = script.Places.Teams

A = script.Effect.A
B = script.Effect.B
C = script.Effect.C
D = script.Effect.D
E = A:Clone()
F = B:Clone()
G = C:Clone()
H = D:Clone()


function onChatted(message, player)
  if message:sub(1, 5):lower() == ("Floo/"):lower()and isAdmin[player.UserId] then
    for _, child in pairs(player.Character:GetChildren()) do
      if child:IsA("BasePart") then
        spawn(function()
        if message:sub(6):lower() == (PC.Value):lower() then

          local E2 = E:Clone()
          local F2 = F:Clone()
          local G2 = G:Clone()
          local H2 = H:Clone()

          E2.Parent = child
          F2.Parent = child
          G2.Parent = child
          H2.Parent = child

          wait(.5)

          player.Character.HumanoidRootPart.CFrame = (CFrame.new(PC.Location.Value))
          wait(1)
          E2:Remove()
          F2:Remove()
          G2:Remove()
          H2:Remove()



          --Transfig class--

        elseif     message:sub(6):lower() == (TC.Value):lower() then
          local E2 = E:Clone()
          local F2 = F:Clone()
          local G2 = G:Clone()
          local H2 = H:Clone()

          E2.Parent = child
          F2.Parent = child
          G2.Parent = child
          H2.Parent = child

          wait(.5)

          player.Character.HumanoidRootPart.CFrame = (CFrame.new(TC.Location.Value))
          wait(1)
          E2:Remove()
          F2:Remove()
          G2:Remove()
          H2:Remove()

          --Potion class--
        elseif     message:sub(6):lower() == (Dor.Value):lower() then
          local E2 = E:Clone()
          local F2 = F:Clone()
          local G2 = G:Clone()
          local H2 = H:Clone()

          E2.Parent = child
          F2.Parent = child
          G2.Parent = child
          H2.Parent = child

          wait(.5)

          player.Character.HumanoidRootPart.CFrame = (CFrame.new(Dor.Location.Value))
          wait(1)
          E2:Remove()
          F2:Remove()
          G2:Remove()
          H2:Remove()

          --Potion class--
        elseif     message:sub(6):lower() == (Te.Value):lower() then
          local E2 = E:Clone()
          local F2 = F:Clone()
          local G2 = G:Clone()
          local H2 = H:Clone()

          E2.Parent = child
          F2.Parent = child
          G2.Parent = child
          H2.Parent = child

          wait(.5)

          player.Character.HumanoidRootPart.CFrame = (CFrame.new(Te.Location.Value))
          wait(1)
          E2:Remove()
          F2:Remove()
          G2:Remove()
          H2:Remove()


        end
        end)
      else
      end
    end
  end
end


game.Players.PlayerAdded:connect(function(player)
player.Chatted:connect(function(message) onChatted(message, player) end)
end)

Anyone have any ideas?

Thank you.

0
Deprecated members' paradise. User#25115 0 — 5y
0
I recommend that you learn how to use loops and functions to your best advantage. User#25115 0 — 5y
0
Also, please learn how to properly indent for readabilities sake. User#25115 0 — 5y
View all comments (22 more)
0
@Phlegethon5778 what do you mean by properly indent? What's not properly indented? SteamG00B 1633 — 5y
0
This is some of the cleanest code I've ever seen on this site SteamG00B 1633 — 5y
0
And another question, what is deprecated? SteamG00B 1633 — 5y
2
If you have nothing good to say, at least make sure it has something to do with the question SteamG00B 1633 — 5y
0
Don't just say "deprecated" without saying what is deprecated. Also, what is wrong with the indentation? fredfishy 833 — 5y
0
I actually figured out what is deprecated, but funny thing is that in this specific case, Remove() actually can be useful because if it was handled differently, you wouldn't need to re-clone the object from storage, you'd just set the parent of the object to what you want it to be, and the effect would be applied to that part. SteamG00B 1633 — 5y
0
(it was deprecated because it just set the parent to nil instead of destroying it) but as you can see, it can be used to basically put it into a sort of cryosleep state. SteamG00B 1633 — 5y
0
Now the only problem with that is that you'd have to do your own garbage collection or else it will slow down the client's computer even after they closed roblox SteamG00B 1633 — 5y
1
@Phlegethon5778 Also forgot to link you to this wonderful guide that you should definitely read: https://scriptinghelpers.org/help/community-guidelines SteamG00B 1633 — 5y
0
@SteamG0D, I have read through all of the guidelines before. I am not new to this. I used to have 1800+ reputation. I was commenting that the person should consider using functions and loops and non-deprecated garbage in their code. As for you, you posted an answer which only makes the code "work" and does not address the many issues present in this script. User#25115 0 — 5y
0
Not only that, but you used deprecated code in your answer, and criticized me for saying nothing "good," when in fact, I was pointing out an area of improvement directly related to the problem. User#25115 0 — 5y
0
As for the rest of you, improper indentation occurs on line 23 and 112. Also, there is a pointless else on line 113. The deprecated method used is Remove, and it is used profusely. As for my comment referring to functions and loops, this script could be shortened significantly by the use of proper code flow and logic. My comments my have been a little sarcastic, but in the end, User#25115 0 — 5y
0
they actually address some bigger issues than the code not working properly. When proper logic and methods are learned, the rest falls into place. User#25115 0 — 5y
0
That is coming from someone who managed to lose 1700 reputation though, and judging by how seriously you take missed indentation (3 lines out of 120 lines!) I can see why that happened. SteamG00B 1633 — 5y
0
And I already explained exactly why they deprecated the code, and also provided an example of how it can be taken advantage of even though it is deprecated SteamG00B 1633 — 5y
0
Also, I recommend looking at https://scriptinghelpers.org/help/community-guidelines just one more time, it seems as if you missed quite a few things in there. SteamG00B 1633 — 5y
0
I did not lose 1700 reputation, look at my account. I deleted the account in order to start over (with no questions asked). User#25115 0 — 5y
0
Also, you don't "take advantage" of deprecated code. You get rid of it. Please stop encouraging bad practices. User#25115 0 — 5y
0
In your answer you do not really teach anything new, you don't encourage proper practice, and over all, your answer contains little to no explanation and is just a "take this and use it." User#25115 0 — 5y
1
Just because code works does not mean it is "good." Neither the asker's code, nor the answerer's code is "good." In fact, the answer is worse than the question, because it encourages using the bad practices already extant in the code. User#25115 0 — 5y
0
Where does it encourage bad practices? The indentation you went ballistic over is fine, there is no deprecated code you accused me of encouraging because I didn't include "don't use deprecated code" in my explanation. (really shouldn't reinvent the wheel here, it was already said once) SteamG00B 1633 — 5y

1 answer

Log in to vote
1
Answered by
SteamG00B 1633 Moderation Voter
5 years ago
Edited 5 years ago

https://scriptinghelpers.org/help/community-guidelines

  1. Do not be a jerk.

  2. Malicious or targeted repeated reputation changes are not permitted.

If you attempt to downvote this answer, you will see you have no reason to do so because I have changed it.

This question is days old (previously working on this before the question was posted), and I have been working on fixing it with her this entire time. If you think I am suggesting that you use deprecated functions just because I'm using her code as an example of what to do, then you are being over critical.

local isAdmin = {[14946581] = true, [28433911] = true, [51013956] = true}

PC = script.Places.PotionClass
TC = script.Places.TransfigClass
Dor = script.Places.Dorm
Te = script.Places.Teams

local fireplace = {} --would be a table containing all the explorer path's to the floor parts in a fireplace.

A = script.Effect.A
B = script.Effect.B
C = script.Effect.C
D = script.Effect.D
E = A:Clone()
F = B:Clone()
G = C:Clone()
H = D:Clone()


function onChatted(message, player)
  if message:sub(1, 5):lower() == ("Floo/"):lower()and isAdmin[player.UserId] then
    fireplace[0].Touched:Connect(function(hit)
    if player == hit then
            a(player, message)
        end
     end
  end
end

game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(message) onChatted(message, player) end)--AAAAAH IT WAS NOT PROPERLY INDENTED, THE WORLD'S GOING TO END!!!!
end)

I just wrapped what you had there in a touched event just after the chat command event.

THIS IS THE ONLY EXPLANATION NEEDED, ALL SHE ASKED WAS WHERE TO PLACE IT!

0
"If you think I am suggesting that you use deprecated functions just because I'm using her code as an example of what to do, then you are being over critical." This is ridiculous. User#25115 0 — 5y
0
By its very usage you are literally saying, "You use this. I use this. All is good." User#25115 0 — 5y
0
Inaction is the same as encouragement in this case. User#25115 0 — 5y
0
oh? Only in this case? SteamG00B 1633 — 5y
Ad

Answer this question