Tsunami Model not Dishing Out Damage?

Hey everyone (again)

So I’m trying to work on my natural disasters factor of my game, but this tsunami model won’t do damage.

My script in the model:

while true do
	wait(3)
	if script.Parent.Parent == workspace then
		local tweenInfo = TweenInfo.new(50, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)
		local tweenService = game:GetService("TweenService")
		local tween = tweenService:Create(script.Parent.Wave, tweenInfo, {Position = Vector3.new(-2191.55, 10.5, 388.4)})
		script.Parent.OnTouchEnabled.Value = true
		tween:Play()
		script.Parent.Wave.CanCollide = true
	end
end

script.Parent.Wave.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 25
		print("Damage from Tsunami on "..hit.Parent.Name.."!")
	elseif hit.Parent.Name == "Tree" then
		hit.Parent.Orientation = Vector3.new(0,90,0)
		print("Hit a tree!")
	end
end)

And the Explorer:
image

Thanks!

you have a while loop above the touched function so the .Touched event won’t fire

1 Like

OHHH! Thanks so much! Seems like an easy fix… :man_facepalming:

1 Like

I recommend to coroutine wrap your while loops:

coroutine.wrap(function() 
while true do
	wait(3)
	if script.Parent.Parent == workspace then
		local tweenInfo = TweenInfo.new(50, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)
		local tweenService = game:GetService("TweenService")
		local tween = tweenService:Create(script.Parent.Wave, tweenInfo, {Position = Vector3.new(-2191.55, 10.5, 388.4)})
		script.Parent.OnTouchEnabled.Value = true
		tween:Play()
		script.Parent.Wave.CanCollide = true
	end
end
end)() 

Because then the thread can continue.