generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: I don't get why this particular line of code doesn't work

Previous Thread :: Next Thread 
Nenno is not online. Nenno
Joined: 14 Oct 2009
Total Posts: 9208
03 Jan 2016 06:09 AM
function Click(mouse)
game.Workspace.Player.Instance.new("ForceField")
end

function Unclick(mouse)
game.Workspace.Player.Destroy("ForceField")
end





function Select(mouse)
mouse.Button1Down:connect(function() Click(mouse) end)
mouse.Button1Up:connect(function() Unclick(mouse) end)
end
Report Abuse
eqis is not online. eqis
Joined: 31 Dec 2008
Total Posts: 295
03 Jan 2016 06:46 AM
That's not how Instance works. You use new as a constructor. For example:

function Click(mouse)
local forcefield = Instance.new("ForceField", workspace.Player)
end

function Unclick(mouse)
local forcefield = workspace.Player:FindFirstChild("ForceField")
if forcefield then
forcefield:Destroy()
end
end

Report Abuse
Egzekiel is not online. Egzekiel
Joined: 10 Jan 2011
Total Posts: 1079
03 Jan 2016 06:48 AM
You're not doing it right

local ff=Instance.new("ForceField",game.Workspace.Player)
And
game.Workspace.Player.ForceField:Destroy()


Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
03 Jan 2016 06:58 AM
function Click(mouse)
game.Workspace.Player.Instance.new("ForceField") --problematic
end

function Unclick(mouse)
game.Workspace.Player.Destroy("ForceField") --problematic
end

function Select(mouse)
mouse.Button1Down:connect(function() Click(mouse) end)
mouse.Button1Up:connect(function() Unclick(mouse) end)
end

Okay so for this line, what you don't understand is the concept of Roblox's hierarchy system. Game is like a folder. Game has another folder workspace in it. Workspace has many folders or objects such as parts and spawnpoints. Since you know the players name, that's great! In Roblox, they have given us libraries. Instance is one of those libraries. These libraries HOLD FUNCTIONS and FIELDS for you to modify or call(execute). Instance is an library and, since we use . to transverse through the 'folders', we do not use . to do this.
game.Workspace.Player.Instance.new("ForceField") --problematic

Here is the correct way:
local ForceField = Instance.new("ForceField") --new is a function inside the library Instance, which will set ForceField pointing to a new ForceField it creates
ForceField.Parent = game.Workspace.Player --Parent is like a folder, but its a Field. It's something that holds like a number or something. In this case, it holds the parent of this part. So we tell that ForceField exists inside of the 'folder' game.Workspace.Player

Knowing all of this, this line should be much easier to modify. Destroy is a METHOD or FUNCTION inside of many instances which are created from the library Instance. Instances are objects that you can manipulate, such as Part, SpawnPoint, etc.
game.Workspace.Player.Destroy("ForceField")

Should be used with : and you need to point to the actual forcefield. So you need to transverse through the player and select the ForceField object that was created using Instance.
game.Workspace.Player.ForceField -- this is the force field you created. To destroy it, use the METHOD :Destroy()

game.Workspace.Player.ForceField:Destroy()
Report Abuse
CoolScience2020 is not online. CoolScience2020
Joined: 29 Dec 2015
Total Posts: 139
03 Jan 2016 07:00 AM
I have coded in c# Java but this is a little weird strange why it dosnt use brackets and semicolons.

But no mater what you are using you need to create a new instance of that object.

Same with parts in a scean.
Report Abuse
Nenno is not online. Nenno
Joined: 14 Oct 2009
Total Posts: 9208
03 Jan 2016 07:01 AM
Okay, thanks guys
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
03 Jan 2016 07:03 AM
"I have coded in c# Java but this is a little weird strange why it dosnt use brackets and semicolons.

But no mater what you are using you need to create a new instance of that object.

Same with parts in a scean."

Shut up
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image