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

Word in script have spaces and doesn`t work?

Asked by 5 years ago

Hello guys, I have a Team name: "Alpin doctor" and this name have a space between the two words and then the script don`t work. (The scripts open a door when a player in the team touch it)

If I let a space between the words the second line have a problem. I tested also this: game.Teams.['Alpine doctor'] and this game.Teams.('Alpine doctor') and alos this game.Teams.["Alpine doctor"] and this game.Teams.'Alpine doctor' Here is the script:

local team = game.Teams.Alpine doctor
local door = script.Parent
door.Touched:connect(function(hit)

Here is the full script

ocal team = game.Teams.Alpine doctor
local door = game.Workspace.STOPP.medicdoor
door.Touched:connect(function(hit)
 local humanoid = hit.Parent:FindFirstChild("Humanoid")
 if humanoid then
  local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
  if plr.Team == team then
   door.CanCollide = false
   door.Transparency = .5
   wait(1)
   door.CanCollide = true
   door.Transparency = 0
  else
   humanoid.Health = 0
  end
 end
end)

Thanks for any help in previous

2 answers

Log in to vote
1
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
5 years ago

You haven't gotten the syntax right, game.Teams["Alpine doctor"] is the way to index a name that dot syntax won't work for, just like writing table[1] and not table.[1]

Alternatively, game.Teams:FindFirstChild("Alpine doctor")

0
Thanks, I did not think of that. Thanks you a lot. DieStockEnte 11 — 5y
Ad
Log in to vote
1
Answered by 5 years ago

Hello,

Here's a quick answer to your question.

To call anything with a space we do,

game.Workspace["Alpine Doctor"]

Notice how there is no "." between Workspace and [Alpine Doctor]. Here's how we would fix your first example,

local team = game.Teams["Alpine doctor"]

I hope this clears up any confusion :)

0
Thank you a lot DieStockEnte 11 — 5y

Answer this question