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

What Is Wrong With This Fire Ball Script?

Asked by
tanzane 100
10 years ago

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

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

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)
0
Players.Player1.Backpack.LocalScript:2: attempt to index global 'Player' (a nil value) This is All I'm Getting tanzane 100 — 10y
0
If you are getting that error then you did not address `Player` vs `LocalPlayer` correctly. Refer to what I have written. BlueTaslem 18071 — 10y
Ad
Log in to vote
1
Answered by 10 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.
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!

Answer this question