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

how to add damaging to this new instance?

Asked by
pwgth 11
3 years ago
Edited 3 years ago

ok fellas, I've met a roadblock. I have this script, and im out of ideas on how to make it so that this darned new instance can cause damage when to players touching it... whether you can help or not, I thank you for reading this...

local tool = script.Parent
local mouse

tool.Equipped:Connect(function(m)
    mouse = m
end)

tool.Activated:Connect(function()
    if mouse then
        local Part = Instance.new("Part",workspace)
        Part.Position = script.parent.Handle.Position
        Part.Material = Enum.Material.Neon
        Part.Size = Vector3.new(0.5,0.5,0.5)
        Part.CanCollide = false
        Part.Anchored = true
--damage thing goes here
    end
end)

sorry for posting a question that's very similar to my previous one but I really cant think of anything since I'm new and I suck at coding.

1 answer

Log in to vote
0
Answered by 3 years ago

All you would need to do is use the variable you set for the part and connect the touched event to deal damage. That would make your script look like this:

local tool = script.Parent
local mouse
local debounce = false 
local dmg = --set damage here

tool.Equipped:Connect(function(m)
    mouse = m
end)

tool.Activated:Connect(function()
    if mouse then
        local Part = Instance.new("Part",workspace)
        Part.Position = script.parent.Handle.Position
        Part.Material = Enum.Material.Neon
        Part.Size = Vector3.new(0.5,0.5,0.5)
        Part.CanCollide = false
        Part.Anchored = true

    Part.Touched:Connect(function(hit)
        local h = hit.Parent:FindFirstChild("Humanoid")
        if h then
            debounce = true
            h:TakeDamage(dmg)
            wait(1)
        end
        debounce = false
    end)
    end
end)

I did a little more than adding touched. One thing I did was add debounce so that the part could only deal damage once every second. The second thing I did was add a variable named "dmg" so you could easily change how much damage the part deals. Hope this helped!

0
also please ask any questions you might have in the comments if you need something explained (or if the code doesn't work). cmgtotalyawesome 1418 — 3y
0
thanks, your a life saver! pwgth 11 — 3y
Ad

Answer this question