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

Another way to use the Touched event?

Asked by
yurhomi10 192
10 years ago

The touched event is great when it comes to a player touching a brick, but what about being able to award points whenever the player is on the same spot or brick for a couple seconds, then the touched event wouldn't really work.

how exactly would I make this, like make a player lose 1 hp every second its on the base part and if its not, the player wouldn't lose damage?

script.Parent.Touched:connect(function(hit)
human = hit.Parent.Humanoid
human.Health = human.Health - 1
wait(1) -- it doesnt make sense, help?
end)

2 answers

Log in to vote
0
Answered by 10 years ago
active=false
script.Parent.Touched:connect(function(hit)
human = hit.Parent:FindFirstChild("Humanoid")
if human then
active=true
while active==true do
human:TakeDamage(1)
wait()
end
end
end)

script.Parent.StoppedTouching:connect(function(hit)
active=false --This right here basically makes the while loop at the top stop,
--because if you notice it basically says "while active is true do this.."
end)

Please note that I haven't tested this, but it should work.

0
Thanks it works :D, though it would be nice if you could add a little comment towards the end exactly what the line does yurhomi10 192 — 10y
0
I tried to explain, but that's not something I'm good at. TheGuyWithAShortName 673 — 10y
Ad
Log in to vote
0
Answered by 10 years ago
script.Parent.Touched:connect(function(hit)
human = hit.Parent.Humanoid
human.Health = human.Health - 1
wait(1) 
end

If you want, just create a loop for when the human is still in contact, also the wait(1) is how long until the scirpt ends, try this maybe.

script.Parent.Touched:connect(function(hit)
human = hit.Parent.Humanoid
human.Health = human.Health - 1
wait(1) 
human = hit.Parent.Humanoid
human.Health = human.Health - 1
wait(1) 
human = hit.Parent.Humanoid
human.Health = human.Health - 1
wait(1) 
end

Now i can't promise it working but there's a possibility.

0
No, this won't work for what the asker is wanting. TheGuyWithAShortName 673 — 10y

Answer this question