Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can you insert a forcefield to a player's Torso?

I am trying to make it so before the explosion is inserted into the game it gives the user of the tool a forcefield. the entire script is ok except the one line on inserting the FF. Here is the chunk of the script I am having problems with -

	local dir = (target - torso.Position) * Vector3.new(1, 0, 1)
	newBV = nil
	if dir.magnitude > .01 then 
		-- make 'em dash forwards too
		dir = dir.unit
		intance.new(ForceField).Character.Torso --This line is the one that is not working.
		newBV = Instance.new("BodyVelocity")
		newBV.P = 100000
		newBV.maxForce = Vector3.new(newBV.P, 0, newBV.P)
		newBV.velocity = dir * 50
		newBV.Parent = torso

		torso.CFrame = CFrame.new(torso.Position, target * Vector3.new(1, 0, 1) + Vector3.new(0, torso.Position.Y, 0))
	end

3 answers

Change line six to the following:

Instance.new("ForceField", Character.Torso)

The second argument of Instance.new() enables you to "give it" a parent to which the object will be parented. The issue with what you were doing was the fact that you didn't spell "Instance" correctly. You were also not parenting it but rather attempting to get/use a property named "Character", which doesn't exist for the given object.

Also, in regards to the squiggly underlines, if you hover over a specific underlined item it will tell you the issue with it.

Instance.new() is how you can create any Instance.

Instance.new("Forcefield")

The above will create a forcefield, but it doesn't have a parent. To give it a parent you can use..

Instance.new("Forcefield", Character.Torso) -- Parents the 'Forcefield' to the Characters Torso

or

local forcefield = Instance.new("Forcefield") -- Creates a variable called forcefield and its value is the new 'Forcefield' Instance
forcefield.Parent = Character.Torso -- This parents the forcefield variable to Character.Torso

Either of the above will work.

So just change line 6 in your code to either of these, preferably the first one as its a bit easier to use and shorter.

If this helped then remember to rate +1 and accept answer for others who have problems with the same question.

  • NinjoOnline

You misspelled Instance.new which might be the issue so change

intance.new(ForceField).Character.Torso

to

Instance.new("ForceField").Character.Torso

3 comments

0

No it is still saying the line below it is wrong so it is still wrong

0

What does it say in the Output? Also, I forgot to include quotes on ForceField.

0

For this, it would be: Instance.new("ForceField", Character.Torso)

This discussion is preserved as it was. New answers, comments, and votes are closed.