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 5 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:

script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid")~= nil then
        hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 20
        script.Parent:remove()
    end
end)

Respond ASAP, Thanks!

0
first of all the remove function is deprecated in favor of :Destroy() theking48989987 2147 — 5y
0
Do what he said ^. Also, is it a server script or local script? It needs to be a server script. blazar04 281 — 5y
0
yea use the "TakeDamage()" Methed as using the "Health" Method changes the health at a "Strange eneral" for some reason. Tizzel40 243 — 5y
0
@ItzFoxz It's a server script, thanks for the advice. T0BIUCHIHAA 11 — 5y
View all comments (4 more)
0
Do you have a RemoteEvent? fr2013 88 — 5y
0
Also is it a tool or when pressing a key to fire it? fr2013 88 — 5y
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 — 5y
0
Alright hold on fr2013 88 — 5y

2 answers

Log in to vote
0
Answered by 5 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)

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

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

game.Workspace.Fired.OnServerEvent:Connect(function(Player) -- Finds the RemoteEvent
    local AlreadyTouched = false
    local Character = Player.Character or Player.CharacterAdded:wait() -- Finds a Player
    local Fireball = script.Parent -- Finds the Fireball you created 

    Fireball.Touched:Connect(function(Hit)
            local Humanoid = Hit.Parent:FindFirstChild("Humanoid") --Finds the Player that has "Humanoid"

            if Humanoid == nil then return end

            if AlreadyTouched == false then
                AlreadyTouched = true -- If it touches, then it'll activate this
                local debris = game:GetService("Debris")
                    if Humanoid then 
                        local creatorTag = Instance.new("ObjectValue") -- Creates a tag like a tool
                        creatorTag.Value = Player
                        creatorTag.Name = "creator"
                        creatorTag.Parent = Humanoid
                        debris:AddItem(creatorTag, 1)
                    end;
                if Humanoid.Parent == Character then
                    Humanoid.Health = Humanoid.Health - 0
                else
                    Humanoid.Health = Humanoid.Health - Humanoid.MaxHealth/2 -- Change the damage
                    Fireball:Destroy() -- If it hits the player, it'll disappear (You can delete this if you want to)
                end
            end
    end)
end)

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 — 5y
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 — 5y
0
@T0BIUCHIHAA Alright add me in Team Create then fr2013 88 — 5y

Answer this question