Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I go about damaging a player once if they touch a part?

I am making a skill and if they were to get hit it would hit them one time. How would I do this exactly? My script is this:

game.ReplicatedStorage.Events.DevilFruits.playerFiredPistol.OnServerEvent:Connect(function(Player, mousePos)
	local Character = Player.Character or Player.CharacterAdded:Wait()
	local NewArm = game.ReplicatedStorage:WaitForChild("GomuGomuArm"):Clone()
	local Arm1 = Character:WaitForChild("RightLowerArm")
	local Arm2 = Character:WaitForChild("RightUpperArm")
	local Arm3 = Character:WaitForChild("RightHand")
	local Humanoid = Character:WaitForChild("Humanoid")
	local Root = Character:WaitForChild("HumanoidRootPart")
	NewArm.Color = Arm1.Color
	NewArm.Position = Arm3.Position
	NewArm.Parent = workspace
	NewArm.Orientation = Root.Orientation
	Arm1.Transparency = 1
	Arm2.Transparency = 1
	Arm3.Transparency = 1
	local vel = Instance.new("BodyVelocity", NewArm)
	vel.Velocity = NewArm.CFrame.LookVector * 100
	wait(.45)
	NewArm:Destroy()
	Arm1.Transparency = 0
	Arm2.Transparency = 0
	Arm3.Transparency = 0
end)

I am planning on adding the damage after body velocity. I do not need help with the script its self but mostly how to damage the player ONCE. I was going to use :

part.Touched:connect(function(hit)
       if hit.Parent:FindFirstChild("Humanoid") then
               local target = hit.Parent
               target:FindFirstChild("Humanoid"):TakeDamage(30)
       end)
end

but that will damage the player to death. Please help me.

1 answer

✓ Accepted answer

You could add a variable to stop it

local stopdmg = false
function onTouch(hit)
	if hit.Parent:FindFirstChild("Humanoid") and not stopdmg then 
		hit.Parent.Humanoid:TakeDamage(30)
	end
	stopdmg = true
end

script.Parent.Touched:Connect(onTouch)

3 comments

0

Didnt take away damage.....

0

Didnt take away damage.....

0

Lemme fix it

This discussion is preserved as it was. New answers, comments, and votes are closed.