Vsevolod
Vsevolod

Reputation: 1

Roblox lua. Spaces in the area name

Need to find out whether the player has unlocked the area or not. Everything works perfectly with areas in the name of which there are no spaces, and the script refuses to work with spaces. Who is not difficult, please help. It should work with the "Neutral Area" and "Future Area".

local player = game.Players.LocalPlayer
local msg = Instance.new("Message", player.PlayerGui)

if (game.Players.LocalPlayer.AREAS.Neutral Area.Value == true) then
msg.Text = "true"
else
msg.Text = "false"
end
wait (2)
msg:Destroy()

Upvotes: 0

Views: 598

Answers (1)

Piglet
Piglet

Reputation: 28974

You cannot have spaces in Lua names. So this indexing operation is invalid!

game.Players.LocalPlayer.AREAS.Neutral Area

Usually you would use a name like NeutralArea or Neutral_Area.

The proper way to index a field named Neutral Area is

game.Players.LocalPlayer.AREAS["Neutral Area"]

t.name is syntactic sugar for t["name"] which only works if the key is actually a valid Lua name/identifier. Valid Lua names consist of underscore and alphanumeric characters. But they may not start with a number...

Please read the Lua manual. This is very basic knowledge.

Upvotes: 3

Related Questions