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

How can I make a part only damage a player once?

Asked by 7 years ago

kind of self explanatory

local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()

game:GetService("UserInputService").InputBegan:connect(function(input,proc)
    if  input.KeyCode == Enum.KeyCode.N then
script.Disabled = true
    local anim = Instance.new("Animation")
anim.AnimationId = 'rbxassetid://865973063'
local loadanim = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(anim)
loadanim:Play()
local x = Instance.new("Part", workspace)
    x.Anchored = false
    x.CanCollide = false
    x.Material = "Neon"
    x.Transparency = 1
    x.Size = Vector3.new(2.5,2.5,2.5)
    x.BrickColor = BrickColor.new("Cyan")
    x.CFrame = player.Character.RightHand.CFrame*CFrame.new(0,0,0)
local weld = Instance.new("Weld", x)
weld.Part0 = x
weld.Part1 = game.Players.LocalPlayer.Character["RightHand"]
local aa = script.particle1:Clone()
aa.Parent = x
game.Debris:AddItem(x,0.8)
x.Touched:connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent.Humanoid ~= player.Character.Humanoid then
   Hit.Parent.Humanoid:TakeDamage(16)
end
end
)
wait(3)
script.Disabled = false
end
end
)
0
you can't use script.Disabled = false because the script is disabled so it won't run that line so it will stay disabled abnotaddable 920 — 7y

1 answer

Log in to vote
1
Answered by 7 years ago

If you want it only damage once, and only once and never again. You can create a variable so that it will only damage once. Since your script is pretty long, I will show my example;

local hit = 0 -- the variable you need
local p =script.Parent

p.Touched:Connect(function(H)
    if hit = 0 then -- only works if hit is 0
        hit = 1 -- hit becomes 1 so it won't damage again
        -- Do damage script
    end
end)

if you want the ball to do damage again then just make hit = 0 again at the end or leave it as 1 forever and it will never do damage EVER again.

Good Luck and Have Fun developing!

0
why 0 and 1 as opposed to true and false? @BlackOrange dragonkeeper467 453 — 7y
0
ok thanks izanagi456 4 — 7y
0
You could also use the `Disconnect` function (: Goulstem 8144 — 7y
Ad

Answer this question