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

My fireball damage script isn't doing any damage?

Asked by 6 years ago

So as the title implies, I'm trying to create a damage script for my fireball, however, when fired no damage is done to a humanoid. Here is my script:

1script.Parent.Touched:connect(function(hit)
2    if hit.Parent:FindFirstChild("Humanoid")~= nil then
3        hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 20
4        script.Parent:remove()
5    end
6end)

Respond ASAP, Thanks!

0
first of all the remove function is deprecated in favor of :Destroy() theking48989987 2147 — 6y
0
Do what he said ^. Also, is it a server script or local script? It needs to be a server script. blazar04 281 — 6y
0
yea use the "TakeDamage()" Methed as using the "Health" Method changes the health at a "Strange eneral" for some reason. Tizzel40 243 — 6y
0
@ItzFoxz It's a server script, thanks for the advice. T0BIUCHIHAA 11 — 6y
View all comments (4 more)
0
Do you have a RemoteEvent? fr2013 88 — 6y
0
Also is it a tool or when pressing a key to fire it? fr2013 88 — 6y
0
@fr2013 It dosen't have a remoteevent because I don't really have any exprience with using them, and its a key to fire. T0BIUCHIHAA 11 — 6y
0
Alright hold on fr2013 88 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

Firstly, never use deprecated functions, read this to know more about deprecated functions and instances. Secondly you should use Humanoid:TakeDamage(20) as its more efficient and less messy then hit.Parent.Humanoid.Heath = hit.Parent.Humanoid.Health - 20.

Here is the fixed code (I tested this in studio so I know it works)

1script.Parent.Touched:Connect(function(hit)
2    if hit.Parent:FindFirstChild("Humanoid")~= nil then
3        hit.Parent.Humanoid:TakeDamage(20)
4        script.Parent:Destroy()
5    end
6end)
0
glad it could help. LoganboyInCO 150 — 6y
0
Uhh, the code didn't work for me, output says "Touched is not a valid member of LocalScript" T0BIUCHIHAA 11 — 6y
0
Is it in a local script or server script? LoganboyInCO 150 — 6y
Ad
Log in to vote
0
Answered by
fr2013 88
6 years ago
Edited 6 years ago

First create a RemoteEvent in Workspace and name it "Fired" Then implement this in the script:

01game.Workspace.Fired.OnServerEvent:Connect(function(Player) -- Finds the RemoteEvent
02    local AlreadyTouched = false
03    local Character = Player.Character or Player.CharacterAdded:wait() -- Finds a Player
04    local Fireball = script.Parent -- Finds the Fireball you created
05 
06    Fireball.Touched:Connect(function(Hit)
07            local Humanoid = Hit.Parent:FindFirstChild("Humanoid") --Finds the Player that has "Humanoid"
08 
09            if Humanoid == nil then return end
10 
11            if AlreadyTouched == false then
12                AlreadyTouched = true -- If it touches, then it'll activate this
13                local debris = game:GetService("Debris")
14                    if Humanoid then
15                        local creatorTag = Instance.new("ObjectValue") -- Creates a tag like a tool
View all 29 lines...
0
Also connect the RemoteEvent from workspace with the key you're pressing. If you need help doing that, then I'm happy to help. fr2013 88 — 6y
0
@fr2013 can you help me fix the whole thing? I think its broken and I have no idea how to fix it, i tried your way and it still didn't know. Tell me if you want me to add you to teamcreate, thanks... T0BIUCHIHAA 11 — 6y
0
@T0BIUCHIHAA Alright add me in Team Create then fr2013 88 — 6y

Answer this question