View difference between Paste ID: 75BU5GeT and mKH39EHC
SHOW: | | - or go back to the newest paste.
1
local player = game:GetService("Players").LocalPlayer -- :GetService() is optional, if Players is renamed, this will still get Players, unlike game.Players
2
local mouse = player:GetMouse() --GetMouse is deprecated but works and is more simpler than UserInputService in my opinion
3
4
function wave()
5
	coroutine.resume(coroutine.create(function()
6
		local pos = mouse.Hit -- CFrame, the target for part to move towards
7
		local part = Instance.new("Part")
8
		part.CFrame = player.Character.Torso.CFrame
9
		part.Anchored = true -- Object is stationary, can only be moved when Position or CFrame is modified
10
		part.CanCollide = false -- Objects can go through the part
11
		part.Transparency = 0
12
		part.Size = Vector3.new(1, 1, 1)
13
		part.Parent = workspace
14
		for i = 1, 20 do
15
			wait()
16
			print(i)
17
			part.Touched:Connect(function(hit)
18
					for i,v in pairs(hit.Parent:GetChildren()) do
19
						if v:IsA("Humanoid") == true then
20-
							hit.Parent:FindFirstChild("Humanoid"):TakeDamage(math.huge)
20+
							hit.Parent:FindFirstChild("Humanoid"):Destroy()
21
					end
22
				end
23
			end)
24
			part.CFrame = part.CFrame:lerp(pos, i/20)
25
			part.Transparency = part.Transparency + .05
26
			part.Size = part.Size + Vector3.new(2, 2, 2)
27
		end
28
		if part.Transparency >= 1 then
29
			part:Destroy()
30
		end
31
	end))
32
end
33
34
35
mouse.Button1Down:Connect(function() -- Whenever mouse is clicked
36
	coroutine.resume(coroutine.create(function()
37
		while wait() do
38
			wave()
39
		end
40
	end))
41
	-- Write the code now to move the part towards the position 'pos'
42
end)