korky5000
|
  |
| Joined: 20 Aug 2008 |
| Total Posts: 228 |
|
|
| 19 Jan 2013 08:39 AM |
Alright so I got this to work: function onTouched(part) local h = part.Parent:findFirstChild("Humanoid") if h~=nil then h.Health = h.Health -5 wait(0.5) h.Health = h.Health -5 wait(0.5) h.Health = h.Health -5 wait(0.5) h.Health = h.Health -5 wait(0.5) h.Health = h.Health -5 wait(0.5) h.Health = h.Health -5 wait(0.5) h.Health = h.Health -5 wait(0.5) h.Health = h.Health -5 wait(0.5) h.Health = h.Health -5 wait(0.5) h.Health = h.Health -5 wait(0.5) h.Health = h.Health -5 wait(0.5) h.Health = h.Health -5 wait(0.5) h.Health = h.Health -5 wait(0.5) h.Health = h.Health -5 wait(0.5) h.Health = h.Health -5 wait(0.5) h.Health = h.Health -5 wait(0.5) h.Health = h.Health -5 wait(0.5) h.Health = h.Health -5 wait(0.5) h.Health = h.Health -5 wait(0.5) h.Health = h.Health -5
end end
script.Parent.Touched:connect(onTouched)
But the problem is I'd like it to not hurt you when you stop touching the brick. Any ideas? |
|
|
| Report Abuse |
|
|
|
| 19 Jan 2013 08:55 AM |
Very inefficient script... What you could use is:
repeat h.Health = h.Health -5 wait(.5) until h.Health <= 0
I'm working on your script.
~ṡсɾïρτïṉģ hεlρεɾṡ ۩ lυαlεαɾṉεɾṡ ④ øƒвќṃṿј~ ღ ▂▃▅▆█ρεώḋïερïε☄сυτïερïε█▆▅▃▂ღ 【▬】 |
|
|
| Report Abuse |
|
|
8SunTzu8
|
  |
| Joined: 30 Sep 2011 |
| Total Posts: 8199 |
|
|
| 19 Jan 2013 09:00 AM |
local touching = false local time = 0.5 local damage = 5
function Stop() touching = false end
function onTouched(part) local human = part.Parent:FindFirstChild("Humanoid") if human then touching = true part.TouchEnded:connect(Stop) while touching do human.Health = human.Health - damage wait(time) end end end
script.Parent.Touched:connect(onTouched)
That's my best guess. I am connecting an event that should fire when the player stops touching it the brick. When it fires, it should stop the while loop that is damaging the player.
"If you want to become a Developer or Innovator for CSA, contact me." |
|
|
| Report Abuse |
|
|
8SunTzu8
|
  |
| Joined: 30 Sep 2011 |
| Total Posts: 8199 |
|
|
| 19 Jan 2013 09:02 AM |
I am not sure if it will break if your health reaches 0, so...
local touching = false local time = 0.5 local damage = 5 local debounce = true
function onTouched(part) local human = part.Parent:FindFirstChild("Humanoid") if human and debounce then touching = true debounce = false part.TouchEnded:connect(Stop) while touching do if human.Health > 0 then human.Health = human.Health - damage wait(time) end end end wait(3.5*(time*1.5)) debounce = true end
function Stop() touching = false end
script.Parent.Touched:connect(onTouched)
"If you want to become a Developer or Innovator for CSA, contact me." |
|
|
| Report Abuse |
|
|
8SunTzu8
|
  |
| Joined: 30 Sep 2011 |
| Total Posts: 8199 |
|
|
| 19 Jan 2013 09:03 AM |
Debounce time is for fun, you probably want it to just be: wait(time).
"If you want to become a Developer or Innovator for CSA, contact me." |
|
|
| Report Abuse |
|
|
|
| 19 Jan 2013 09:09 AM |
Here is my idea. I tested it and it works. Put a script in the part, and put another script in the script... Here's an example hierarchy:
-Part --Script ---Kill Script
Okay, so here's the script that will go under part:
-----------------------------------------------------------------
local part = script.Parent local killscript = script["Kill Script"]
part.Touched:connect(function (hit)
if debounce then return end; debounce = true
local human = hit.Parent:findFirstChild("Humanoid") if human then local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player and player.Character then local new_killscript = killscript:clone() new_killscript.Parent = player.Character new_killscript.Disabled = false end end
debounce = nil
end)
part.TouchEnded:connect(function (hit)
local human = hit.Parent:findFirstChild("Humanoid") if human then local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player and player.Character then if not player.Character:findFirstChild("Kill Script") then return end player.Character["Kill Script"]:Destroy() end end
end)
-----------------------------------------------------------------
Here's the part that will go in the Kill Script:
-----------------------------------------------------------------
local character = script.Parent local humanoid = character.Humanoid
if character and humanoid then repeat humanoid.Health = humanoid.Health -5 wait(0.5) until humanoid.Health <= 0 end
-----------------------------------------------------------------
Tested, it works. ^.^
~ṡсɾïρτïṉģ hεlρεɾṡ ۩ lυαlεαɾṉεɾṡ ④ øƒвќṃṿј~ ღ ▂▃▅▆█ρεώḋïερïε☄сυτïερïε█▆▅▃▂ღ 【▬】 |
|
|
| Report Abuse |
|
|
8SunTzu8
|
  |
| Joined: 30 Sep 2011 |
| Total Posts: 8199 |
|
|
| 19 Jan 2013 09:23 AM |
I tested mine and it worked too. It's pretty neat...
I could use that for when people are drowning. Anyway, the TouchedEnded doesn't always work because of the strange physics. Sometimes it ends too quickly, but if you were to keep walking on it, then it'd activate again.
"If you want to become a Developer or Innovator for CSA, contact me." |
|
|
| Report Abuse |
|
|