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

What Is Wrong With This Fire Ball Script?


	mouse = Player:GetMouse()
	
function FireBall()
		X = Instance.new("Part")
	X.Size = Vector3.new(10, 10, 10)
		X.TopSurface = "Smooth"
	X.BottomSurface = "Smooth"
		X.BrickColor = BrickColor.new("Bright Red")
	X.Transparency = 0.4
		X.Shape = "Ball"
	Y = Instance.new("BodyVelocity")
		Y.maxForce = Vector3.new(math.huge, math.huge. math.huge)
	Y.velocity = Players.Player.Character.Torso.CFrame.lookvector*80
X.Parent = Workspace
Y.Parent = X
end

mouse.Button1Down:connect(FireBall)

Towards the end I was a bit "Confused" when I was calling the function. (Also I know I didn't Add In Fire Yet)

2 answers

✓ Accepted answer

This is close to being right. There are three problems I see:

  • X is never given a position, so it's probably in some random space in the center of the baseplate.

  • Players is not defined.

  • The property is LocalPlayer not Player

And also a few things to help clean it up a little.


To elaborate:

Unlike Workspace, the Players service doesn't have a variable already given to you. You have to explicitly use game.Players (see line 13).

And, the local player is .LocalPlayer not .Player (also line 13). (This script will only work as a LocalScript and without FilteringEnabled)


To give X its position, you could do something like

X.Position = game.Players.LocalPlayer.Character.Torso.Position
+ game.Players.LocalPlayer.Character.Torso.CFrame.lookVector * 3

To place it a few studs in front of the player.


Since we would then be referring to the torso object 3 times, it would probably be better to define a variable for it.

function FireBall()
	local torso = game.Players.LocalPlayer.Character.Torso
	...
	Y.Velocity = torso.CFrame.lookVector * 80
	...
	X.Position = torso.Position + torso.CFrame.lookVector * 3
	...

One more convenient detail. Instead of having a line to set the parent of a new object (lines 14, 15 in your snippet) you can use the second parameter to Instance.new:

	local X = Instance.new("Part", Workspace)
	...
	local Y = Instance.new("BodyVelocity", X)

2 comments

0

Players.Player1.Backpack.LocalScript:2: attempt to index global 'Player' (a nil value) This is All I'm Getting

0

If you are getting that error then you did not address Player vs LocalPlayer correctly. Refer to what I have written.

mouse = Player:GetMouse()

function FireBall()
 local torso = game.Players.LocalPlayer.Character.Torso
      local  Fire = Instance.new("Part")
    Fire.Size = Vector3.new(10, 10, 10)
        Fire.TopSurface = "Smooth"
    Fire.BottomSurface = "Smooth"
        Fire.BrickColor = BrickColor.new("Bright Red")
    Fire.Transparency = 0.4
        Fire.Shape = "Ball"
  local  Ball = Instance.new("BodyVelocity")
        Ball.maxForce = Vector3.new(math.huge, math.huge. math.huge)
    Ball.velocity = Players.LocalPlayer.Character.Torso.CFrame.lookvector=80
Fire.Parent = Workspace
Ball.Parent = Fire
end
 
mouse.Button1Down:connect(FireBall)

Try this i did try to edit it an bit I am Not that good At Script So i am sorry if it dont works!

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