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

01local player = game.Players.LocalPlayer
02local Mouse = player:GetMouse()
03 
04game:GetService("UserInputService").InputBegan:connect(function(input,proc)
05    if  input.KeyCode == Enum.KeyCode.N then
06script.Disabled = true
07    local anim = Instance.new("Animation")
08anim.AnimationId = 'rbxassetid://865973063'
09local loadanim = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(anim)
10loadanim:Play()
11local x = Instance.new("Part", workspace)
12    x.Anchored = false
13    x.CanCollide = false
14    x.Material = "Neon"
15    x.Transparency = 1
View all 35 lines...
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;

1local hit = 0 -- the variable you need
2local p =script.Parent
3 
4p.Touched:Connect(function(H)
5    if hit = 0 then -- only works if hit is 0
6        hit = 1 -- hit becomes 1 so it won't damage again
7        -- Do damage script
8    end
9end)

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