Help with GetTouchingParts, please it's been 5 days

I have been trying to figure this out for 5 days straight, making multiple threads with similar issues.
So, let me explain (again.). :sob:

I am trying to make a move that releases a sphere, any NPC or Character parts and decals inside the sphere turn invisible (transparency 1, tweened.) and billboard guis turn to false. It then waits 10 seconds and the parts, decals, billboardguis go visible again. However, apparently my script doesn’t want to do that.
I’ve went through 6 different script rewritings but I can’t seem to fix it. :frowning_face_with_open_mouth:

The way it works, is that I have a tool for doing the move, a remote event and a modulescript to require the move.

Here’s also one problem https://gyazo.com/e2e780addeab685f28ec4692e81da7b5.

Layout of the tool:
image

The moves script detects if the player using the tool presses a key, and if that key is E then it does the move. The localscript then fires the remote event to find the modulescript for the move, and then finally require that modulescript from the server (so that effects will be serversided).

Moves Localscript
local UIS = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")
local Modules = RS:WaitForChild("Modules")
local Fruit = Modules:WaitForChild("Fruit")
local HM = Modules:WaitForChild("Handlers")
local Tool = script.Parent
local Player = game.Players.LocalPlayer
local remote = RS.RemoteEvents.Fruit
local PlayerGui = Player:WaitForChild("PlayerGui")
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Cooldown1 = false
local Holding1 = false
local Cooldown2 = false
local Holding2 = false
local Debounce = 1
local Mouse = Player:GetMouse()
local track1 = Humanoid:LoadAnimation(Tool.Animations.Spin)
local tweeninfo = TweenInfo.new(1.5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
local ts = game:GetService("TweenService")

local function zmove()
	Tool.Active.Value = "Z"
	remote:FireServer("Suke", "Self Invisibility", "Start")
	wait(2)
	for i, v in pairs(Character:GetDescendants()) do
		if (v.Name ~= "HumanoidRootPart" and v:IsA("MeshPart") or v:IsA("Part")  and  v.Name ~= "HumanoidRootPart") then
			v.Transparency = 0.7
		elseif v:IsA("Decal") then
			v.Transparency = 0.7
		end
	end
	wait(10)
	for i, v in pairs(Character:GetDescendants()) do
		if (v.Name ~= "HumanoidRootPart" and v:IsA("MeshPart") or v:IsA("Part")  and  v.Name ~= "HumanoidRootPart") then
			v.Transparency = 0
		elseif v:IsA("Decal") then
			v.Transparency = 0
		end
	end
	remote:FireServer("Suke", "Self Invisibility", "End")
	Tool.Active.Value = "None"
end

local function xmove()
	Tool.Active.Value = "X"
	remote:FireServer("Suke", "Area Invisibility", "Start")
	wait(10)
	Tool.Active.Value = "None"
end

UIS.InputBegan:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.E and Debounce == 1 and Tool.Equip.Value == true and Tool.Active.Value == "None"  and Cooldown1 == false then
		Debounce = 2
		local HIS = Tool.Animations["Area Charge"]
		HoldTrack = Player.Character.Humanoid:LoadAnimation(HIS)
		HoldTrack:Play()
		for i = 1,math.huge do
			if Debounce == 2 then
				local RootPos, MousePos = Player.Character.HumanoidRootPart.Position, Mouse.Hit.Position
				Player.Character.HumanoidRootPart.CFrame = CFrame.new(RootPos, Vector3.new(MousePos.X, RootPos.Y, MousePos.Z))
				Player.Character.HumanoidRootPart.Anchored = true
			else
				break
			end
			wait()
		end
	elseif Input.KeyCode == Enum.KeyCode.Z and Tool.Equip.Value == true and Tool.Active.Value == "None"  and Cooldown1 == false then
		track1:Play()
		zmove()
		Cooldown1 = true
		wait(3)
		Cooldown1 = false
	end
end)

UIS.InputEnded:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.E and Debounce == 2 and Tool.Equip.Value == true and Tool.Active.Value == "None" and Cooldown1 == false then
		Cooldown1 = true
		Debounce = 3
		local PIS = Tool.Animations["Area Release"]
		local PunchTrack = Player.Character.Humanoid:LoadAnimation(PIS)
		PunchTrack:Play()
		HoldTrack:Stop()
		PunchTrack:GetMarkerReachedSignal("Release"):Connect(function()
			xmove()
			task.wait(10)
			Cooldown1 = false
		end)
		wait(1)
		Player.Character.HumanoidRootPart.Anchored = false
		wait(2)
		Tool.Active.Value = "None"
		wait(0.1)
		Debounce = 1
	end
end)
Remote Event
local rs = game:GetService("ReplicatedStorage")
local remote = rs.RemoteEvents.Fruit
local modules = rs.Modules
local fruitmodules = modules.Fruit

remote.OnServerEvent:Connect(function(plr, ability, move, functions, option1, option2)
	if plr then
		for i, k in pairs(fruitmodules:GetChildren()) do
			if k.Name == tostring(ability) then
				local abilitymove = k[move]
				local required = require(abilitymove)
				required[functions](plr, option2)
			end
		end 
	end
end)
Module Script
local functions = {}

function functions.Start(plr)
	local tweeninfo = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
	local tweenservice = game:GetService("TweenService")
	local chr = plr.Character
	local remote = game.ReplicatedStorage.RemoteEvents.Suke.Invisible
	local hum = chr:FindFirstChildOfClass("Humanoid")
	local health = hum.Health
	local cube = script.cube:Clone()
	cube.Parent = workspace.Effects
	cube.Position = chr.HumanoidRootPart.Position
	local tween = tweenservice:Create(cube, tweeninfo, {Size = Vector3.new(50.75, 50.75, 50.75)})
	
	tween:Play()
	tween.Completed:Wait()
	
	local function GetTouchingParts(part)
		local connection = part.Touched:Connect(function() end)
		local results = part:GetTouchingParts()
		connection:Disconnect()
		return results
	end
	
	local debounce = false
	local aoe = GetTouchingParts(cube)
	local targets = {}
	
	for i, a in pairs(aoe) do
		if a:IsDescendantOf(workspace.NPCs) then
			local parent = a.Parent
			if not table.find(targets, parent) then
				for i, p in pairs(parent:GetDescendants()) do
					if (p:IsA("BasePart") or p:IsA("Decal") and p.Name ~= "HumanoidRootPart" and p.Transparency ~= 1) then
						local tween = tweenservice:Create(p, tweeninfo, {Transparency = 1})
						tween:Play()
					elseif p:IsA("BillboardGui") then
						p.Enabled = false
					end
				end
			end
			table.insert(targets, parent)
			print("NPC")
			wait(10)
			if table.find(targets, parent) then
				for i, p in pairs(parent:GetDescendants()) do
					if (p:IsA("BasePart") or p:IsA("Decal") and p.Name ~= "HumanoidRootPart" and p.Transparency ~= 0) then
						local tween = tweenservice:Create(p, tweeninfo, {Transparency = 0})
						tween:Play()
					elseif p:IsA("BillboardGui") then
						p.Enabled = true
					end
				end
			end
		elseif a:IsDescendantOf(workspace.Players) then
			local parent = a.Parent
			local playar = game.Players:GetPlayerFromCharacter(parent)
			if not table.find(targets, parent) then
				for i, p in pairs(parent:GetDescendants()) do
					if (p:IsA("BasePart") or p:IsA("Decal") and p.Name ~= "HumanoidRootPart" and p.Transparency ~= 1) then
						local tween = tweenservice:Create(p, tweeninfo, {Transparency = 1})
						tween:Play()
						remote:InvokeClient(playar, 0.7)
					elseif p:IsA("BillboardGui") then
						p.Enabled = false
					end
				end
			end
			table.insert(targets, parent)
			print("Player")
			wait(10)
			if table.find(targets, parent) then
				for i, p in pairs(parent:GetDescendants()) do
					if (p:IsA("BasePart") or p:IsA("Decal") and p.Name ~= "HumanoidRootPart" and p.Transparency ~= 0) then
						local tween = tweenservice:Create(p, tweeninfo, {Transparency = 0})
						tween:Play()
					elseif p:IsA("BillboardGui") then
						p.Enabled = true
					end
				end
			end
		end
	end
	

	
end

return functions

Here are the scripts. Please help me fix this, it’s been almost a week, 5 days specifically. I do not want this to reach a week to fix, please. Thank you to whoever helps me and finds a way around this…

Are you sure that the circle is a full circle? no holes at all?

It’s a ball partimage
It’s not a mesh or anything else it’s just a sphere

Instead of GetTouchingParts you could use Touched since it’s resizing with TweenService. (I think)

I see, which is more efficient? I think exploiters can exploit the touch event if I’m correct?

Thats the same issue, hackers can exploit GetTouchingParts, too

.Touched and GetTouchingParts do not work for anchored parts being manually moved(like for example with TweenService. To make it work with anchored parts you have to use workspace:GetPartsInPart(part).

1 Like

Oh wait, sorry. I’m pretty sure theres a touched event in the script.

Yeah I’ve tried doing that, except it still doesn’t work like I expected.
If you want the previous rewrited script I had and the issue, here’s the thread: GetPartsInPart() loop not working as expected - #6 by Pan_Shyrikys

Can you describe the exact issue you had in that thread?(the one related to GetPartsInPart())

I wanna make an ability that releases a sphere, and the parts that hit it, if it’s of a character’s then it detects wether the part is a descendant of NPC or Players folder in workspace. Similarly, if it’s a descendant of the Players folder then it’s of a player’s, the same goes for NPCs. But, it’s not working as I expected it would. If the player is a little far from npcs or players(but the npc or player is still touching the sphere when it’s done tweening), then only the player would go invisible, and sometimes a few seconds later the other players or npcs touching the sphere even after it gets destroyed goes invisible.

Let me show you what I mean: https://gyazo.com/b5c62df6df5997316419199060799401

If the player is near: https://gyazo.com/abb2d6753f2d6d768cd99a8982f4b808

sorry if I had bad explaination I’m not good at explaining

sorry, I copy pasted it too xD

local functions = {}

function functions.Start(plr)
	local tweeninfo = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
	local tweenservice = game:GetService("TweenService")
	local chr = plr.Character
	local remote = game.ReplicatedStorage.RemoteEvents.Suke.Invisible
	local hum = chr:FindFirstChildOfClass("Humanoid")
	local health = hum.Health
	local cube = script.cube:Clone()
	cube.Parent = workspace.Effects
	cube.Position = chr.HumanoidRootPart.Position
	local tween = tweenservice:Create(cube, tweeninfo, {Size = Vector3.new(50.75, 50.75, 50.75)})
	
	tween:Play()
	tween.Completed:Wait()
	
	local debounce = false
	local aoe = workspace:GetPartsInPart(cube)
	local targets = {}

	
	for i, a in pairs(aoe) do
		if a:IsA("BasePart") and a.Name ~= "HumanoidRootPart" then
			if a:IsDescendantOf(workspace.NPCs) then
				if a.Parent:FindFirstChildOfClass("Humanoid") then
					if not table.find(targets, a.Parent) then
						for i, d in pairs(a.Parent:GetDescendants()) do
							if (d.Name ~= "HumanoidRootPart" and d:IsA("BasePart") or d:IsA("Decal") and d.Transparency == 0 and d.Name ~= "HumanoidRootPart") then
								local tween = tweenservice:Create(d, tweeninfo, {Transparency = 1})
								tween:Play()
							elseif d:IsA("BillboardGui") then
								d.Enabled = false
							end
							if debounce == false then
								debounce = true
								table.insert(targets, a.Parent)
								print("STARTED NPC")
							end
						end
					end
					wait(10)
					if table.find(targets, a.Parent) then
						for i, d in pairs(a.Parent:GetDescendants()) do
							if (d.Name ~= "HumanoidRootPart" and d:IsA("BasePart") or d:IsA("Decal") and d.Transparency == 1 and d.Name ~= "HumanoidRootPart") then
								local tween = tweenservice:Create(d, tweeninfo, {Transparency = 0})
								tween:Play()
							elseif d:IsA("BillboardGui") then
								d.Enabled = true
							end
						end
						local newtween = tweenservice:Create(cube, tweeninfo, {Size = Vector3.new(0, 0, 0), Transparency = 1})
						newtween:Play()
						newtween.Completed:Wait()
						cube:Destroy()
						if debounce == false then
							debounce = true
							print("ENDED NPC")
						end
					end
				end
			elseif a:IsDescendantOf(workspace.Players) then
				if a.Parent:FindFirstChildOfClass("Humanoid") then
					if not table.find(targets, a.Parent) then
						for i, d in pairs(a.Parent:GetDescendants()) do
							if (d.Name ~= "HumanoidRootPart" and d:IsA("BasePart") or d:IsA("Decal") and d.Transparency == 0 and d.Name ~= "HumanoidRootPart") then
								local tween = tweenservice:Create(d, tweeninfo, {Transparency = 1})
								tween:Play()
								remote:InvokeClient(game.Players:GetPlayerFromCharacter(a.Parent), 0.7)
							elseif d:IsA("BillboardGui") then
								d.Enabled = false
							end
							if debounce == false then
								debounce = true
								table.insert(targets, a.Parent)
								print("STARTED PLR")
							end
						end
					end
					wait(10)
					if table.find(targets, a.Parent) then
						for i, d in pairs(a.Parent:GetDescendants()) do
							if (d.Name ~= "HumanoidRootPart" and d:IsA("BasePart") or d:IsA("Decal") and d.Transparency == 1 and d.Name ~= "HumanoidRootPart") then
								local tween = tweenservice:Create(d, tweeninfo, {Transparency = 0})
								tween:Play()
							elseif d:IsA("BillboardGui") then
								d.Enabled = true
							end
						end
						local newtween = tweenservice:Create(cube, tweeninfo, {Size = Vector3.new(0, 0, 0), Transparency = 1})
						newtween:Play()
						newtween.Completed:Wait()
						cube:Destroy()
						if debounce == false then
							debounce = true
							print("ENDED PLR")
						end
					end
				end
			end
		end
	end
	
end

return functions

Also ignore the sphere’s name being cube, just a little something.

This may be related to the fact you wait for the tween to end, before running any code, and you have to call GetPartsInPart() multiple times. Instead you should do something like this:

local functions = {}

function functions.Start(plr)
	local tweeninfo = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
	local tweenservice = game:GetService("TweenService")
	local chr = plr.Character
	local remote = game.ReplicatedStorage.RemoteEvents.Suke.Invisible
	local hum = chr:FindFirstChildOfClass("Humanoid")
	local health = hum.Health
	local cube = script.cube:Clone()
	cube.Parent = workspace.Effects
	cube.Position = chr.HumanoidRootPart.Position
	local tween = tweenservice:Create(cube, tweeninfo, {Size = Vector3.new(50.75, 50.75, 50.75)})
	
	local ended = false 
	
	--wrapped inside a coroutine so the loop doesn't pause the script
	coroutine.wrap(function()
		while task.wait(.2) do --less wait = more lag, more wait = less precise
			if ended then 
				break 
			end
			local aoe = workspace:GetPartsInPart(cube)
			--paste the rest of the script here
			--starting from local debounce
			--and ending on the last end 
			--you can try making the sphere code a different function and just call it here
		end
	end)() 
	tween:Play()
	tween.Completed:Wait()
end

return functions

Edit: If I where you I would make an entire system for stuff like this, cause honestly I am unable to understand the hell going on in there.

I don’t know if it solved it, but when I’m a little farther from an NPC, it doesn’t turn it visible.
image
And it casually turns some of my parts invisible and visible and invisible, and so on.
image
image
If i’m nearer tho it does turn the npc invisible and waits 10 seconds to turn it visible again. https://gyazo.com/a4a91dfef02c8bef0adaea537e52056e
script:

local functions = {}
local tweenservice = game:GetService("TweenService")
local tweeninfo = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)

local function invisibleplr(remote, character, transparency, condition)
	for i, d in pairs(character:GetDescendants()) do
		if (d.Name ~= "HumanoidRootPart" and d:IsA("BasePart") or d:IsA("Decal") and d.Transparency == 0 and d.Name ~= "HumanoidRootPart") then
			local tween = tweenservice:Create(d, tweeninfo, {Transparency = transparency})
			tween:Play()
			if condition == "Invisible" then
				remote:InvokeClient(game.Players:GetPlayerFromCharacter(character), 0.7)
			end
		elseif d:IsA("BillboardGui") then
			d.Enabled = false
		end
	end
end

local function invisiblenpc(remote, character, transparency)
	for i, d in pairs(character:GetDescendants()) do
		if (d.Name ~= "HumanoidRootPart" and d:IsA("BasePart") or d:IsA("Decal") and d.Transparency == 0 and d.Name ~= "HumanoidRootPart") then
			local tween = tweenservice:Create(d, tweeninfo, {Transparency = transparency})
			tween:Play()
		elseif d:IsA("BillboardGui") then
			d.Enabled = false
		end
	end
end

function functions.Start(plr)
	local chr = plr.Character
	local remotevent = game.ReplicatedStorage.RemoteEvents.Suke.Invisible
	local hum = chr:FindFirstChildOfClass("Humanoid")
	local health = hum.Health
	local Sphere = script.Sphere:Clone()
	Sphere.Parent = workspace.Effects
	Sphere.Position = chr.HumanoidRootPart.Position
	local tween = tweenservice:Create(Sphere, tweeninfo, {Size = Vector3.new(50.75, 50.75, 50.75)})

	local ended = false 

	--wrapped inside a coroutine so the loop doesn't pause the script
	coroutine.wrap(function()
		while task.wait(.2) do --less wait = more lag, more wait = less precise
			if ended then 
				break 
			end
			local aoe = workspace:GetPartsInPart(Sphere)
			local debounce = false
			local targets = {}
			
			for i, a in pairs(aoe) do
				if a:IsA("BasePart") and a.Name ~= "HumanoidRootPart" then
					if a:IsDescendantOf(workspace.NPCs) then
						if a.Parent:FindFirstChildOfClass("Humanoid") then
							if not table.find(targets, a.Parent) then
								invisiblenpc(remotevent, a.Parent, 1)
								if debounce == false then
									debounce = true
									table.insert(targets, a.Parent)
									print("STARTED NPC")
								end
							end
							wait(10)
							if table.find(targets, a.Parent) then
								invisiblenpc(remotevent, a.Parent, 0)
								local newtween = tweenservice:Create(Sphere, tweeninfo, {Size = Vector3.new(0, 0, 0), Transparency = 1})
								newtween:Play()
								newtween.Completed:Wait()
								Sphere:Destroy()
								if debounce == false then
									debounce = true
									print("ENDED NPC")
								end
							end
						end
					elseif a:IsDescendantOf(workspace.Players) then
						if a.Parent:FindFirstChildOfClass("Humanoid") then
							if not table.find(targets, a.Parent) then
								invisibleplr(remotevent, a.Parent, 1, "Invisible")
								if debounce == false then
									debounce = true
									table.insert(targets, a.Parent)
									print("STARTED PLAYER")
								end
							end
							wait(10)
							if table.find(targets, a.Parent) then
								invisibleplr(remotevent, a.Parent, 0, "Visible")
								local newtween = tweenservice:Create(Sphere, tweeninfo, {Size = Vector3.new(0, 0, 0), Transparency = 1})
								newtween:Play()
								newtween.Completed:Wait()
								Sphere:Destroy()
								if debounce == false then
									debounce = true
									print("ENDED PLR")
								end
							end
						end
					end
				end
			end
		end
	end)() 
	tween:Play()
	tween.Completed:Wait()
end

return functions