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

how do i make my barrier do damage?? i need help

i think i need to put the dmg in the touched function, but i dont know what to write. Help.

here is the script:

local Tool = script.Parent

Tool.RemoteEvent.OnServerEvent:Connect(function(Player, Debounce)
local AlreadyTouched = false
local Character = Player.Character
Debounce = true
local Barrier = Instance.new("Part")
Barrier.BrickColor = BrickColor.new("Lime green")
Barrier.Material = "Neon"
Barrier.Transparency = 0.25
Barrier.Anchored = false
Barrier.Size = Vector3.new(8,13,1)
Barrier.Shape = Enum.PartType.Block
Barrier.Locked = true
Barrier.CanCollide = false
Barrier.CFrame = Character.HumanoidRootPart.CFrame
Barrier.Parent = Character
local bv = Instance.new("BodyVelocity")
 bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.Velocity = Character.HumanoidRootPart.CFrame.lookVector * 25
bv.Parent = Barrier


Barrier.Touched:Connect(function(hit)

end)	
	







wait(5)
Barrier:Destroy()
Debounce = false

end)

2 answers

✓ Accepted answer

ok, now I LOVE touched Functions! so ima teach you how you can complete this script

now lets use a little "Parameter" called hit

hit is a little word used for what the part is hitting....

so lets say you want a humanoid to be damaged when hit.Well you can't just simply damage a humanoid that's probably not exsisting in or in this term nil

We have to Find The Humanoid, and we can do this by using the FindFirstChild Technique!

here is a totally cool example down below!

local HitPart = game.Workspace.Part

local damage = 10--Put your Damage Here!

HitPart.Touched:Connect(function(hit)--Yep! lets use hit!

local ehum = hit and hit.Parent:FindFirstChild("Humanoid") or hit.Parent.Parent:FindFirstChild("Humanoid") --now, if hit (which is the hitPart) hits someonse leg, it will get the parent (which is the Character), then search that parent for the humanoid that we are damaging!

if ehum then-- if we found a humanoid... then
ehum:TakeDamage(damage)--Always use The TakeDamage() Method. Using the Health method doesn't protect the user from a force Field and decreases at a strange Eneral…
end
end)

And That's it! I Hoped This Helped you

comment down below if you have any questions Always keep scripting and Good Luck

Have a nice Day!

--T40

1 comment

0

i didnt want the barrier to kill me too........

local Tool = script.Parent

Tool.RemoteEvent.OnServerEvent:Connect(function(Player, Debounce)
local AlreadyTouched = false
local Character = Player.Character
Debounce = true
local Barrier = Instance.new("Part")
Barrier.BrickColor = BrickColor.new("Lime green")
Barrier.Material = "Neon"
Barrier.Transparency = 0.25
Barrier.Anchored = false
Barrier.Size = Vector3.new(8,13,1)
Barrier.Shape = Enum.PartType.Block
Barrier.Locked = true
Barrier.CanCollide = false
Barrier.CFrame = Character.HumanoidRootPart.CFrame
Barrier.Parent = Character
local bv = Instance.new("BodyVelocity")
 bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.Velocity = Character.HumanoidRootPart.CFrame.lookVector * 25
bv.Parent = Barrier


Barrier.Touched:Connect(function(hit)

game.workspace[hit.Parent.Name].humanoid.health = game.workspace[hit.Parent.Name].humanoid.health - --Put amount of desired damage

end)    

wait(5)
Barrier:Destroy()
Debounce = false

end)

If you want to instantly kill the player who touches the barrier then replace it with this.

local Tool = script.Parent

Tool.RemoteEvent.OnServerEvent:Connect(function(Player, Debounce)
local AlreadyTouched = false
local Character = Player.Character
Debounce = true
local Barrier = Instance.new("Part")
Barrier.BrickColor = BrickColor.new("Lime green")
Barrier.Material = "Neon"
Barrier.Transparency = 0.25
Barrier.Anchored = false
Barrier.Size = Vector3.new(8,13,1)
Barrier.Shape = Enum.PartType.Block
Barrier.Locked = true
Barrier.CanCollide = false
Barrier.CFrame = Character.HumanoidRootPart.CFrame
Barrier.Parent = Character
local bv = Instance.new("BodyVelocity")
 bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.Velocity = Character.HumanoidRootPart.CFrame.lookVector * 25
bv.Parent = Barrier


Barrier.Touched:Connect(function(hit)

game.workspace[hit.Parent.Name].humanoid.health = 0

end)    

wait(5)
Barrier:Destroy()
Debounce = false

end)

Tell me if it doesn't work.

2 comments

0

thank u so much!!!!

0

it doesnt work

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