Answered by
8 years ago Edited 8 years ago
Your code
Friaza's tutorial is very useful to get someone use to KeyDown()
functions, and the code you have is ALMOST perfect, however, some parts of your code aren't exactly perfect. For the code to work, you need two scripts: a local script
and a regular script
. Name the local script
'Fireball' and name the script
'Firedamage' (Have Firedamage INSIDE Fireball, and have the code be a child of StarterPack). Now, in the Firedamage code, put this edited code into it (I'll explain the code to the best of my ability...)
Firedamage Code
01 | function onDamage(Part) |
03 | if Part.Parent:FindFirstChild( "Humanoid" ) ~ = nil and Part.Parent.Name ~ = "script.Parent.Name" then |
05 | script.Disabled = true |
07 | local f = Instance.new( 'Fire' , Part) |
13 | Part.Parent.Humanoid.Health = Part.Parent.Humanoid.Health - 1 |
21 | Part.Parent.Humanoid.PlatformStand = true |
23 | script.Parent:remove() |
29 | script.Parent.Touched:connect(onDamage) |
Now, in the Fireball code, you need to put this edited code into it (again, I'll explain to the best of my ability...)
Fireball code
02 | Player = script.Parent.Parent |
04 | mouse = Player:GetMouse() |
08 | function onKeyDown(key) |
10 | local Key = key:lower() |
14 | local x = Instance.new( 'Part' , workspace) |
16 | x.BrickColor = BrickColor.new( "Bright red" ) |
18 | x.Size = Vector 3. new( 10 , 10 , 10 ) |
20 | x.TopSurface = 'Smooth' |
22 | x.BottomSurface = 'Smooth' |
32 | local fd = script.Firedamage:Clone() |
36 | local y = Instance.new( 'BodyVelocity' , x) |
38 | y.maxForce = Vector 3. new( math.huge , math.huge , math.huge ) |
40 | y.velocity = Player.Character.Torso.CFrame.lookVector* 80 |
42 | local f = Instance.new( 'Fire' , x) |
48 | x.CFrame = Player.Character.Torso.CFrame*CFrame.new( 0 , 0 , - 12 ) |
52 | game.Debris:AddItem(x, 1 ) |
54 | print ( 'Fireball successfully worked!' ) |
60 | mouse.KeyDown:connect(onKeyDown) |
In conclusion...
Your code was right, but I have some edits to it to have it cleaner. Let me know if it doesn't work.
Greek