Script stopped working

Yeah, if you want, I can invite you to the game,

1 Like

Does it work for you if the script RunContext is set to Client?

1 Like

Sorry for my late reply. Yes, it does. There’s a pretty noticeable delay, but it works for me regardless.

1 Like

I have no idea why it doesn’t for me. It’s frustrating.

1 Like

i think pairs loop run till they go through every key value pair in table

1 Like

i think it seems like the game has not loaded every part yet, so in your pairs loop the table probably dont contain every part and thats probably the reason why touched is applied to some parts and rest of the parts are ignored

1 Like

I don’t there is a way to do this on the client. If there is, it’s most likely very complicated. I’m going to need some more time to figure this out. Sorry.

1 Like

Hello. I just finished a formula for your script. Try this and see if it works. There may be a slight delay.

local Folder = script.Parent
local Filter = {}

local DB = true

function GetHumanoid(v: BasePart)
	v.Touched:Connect(function(hit)
		local Humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
		
		if Humanoid and Humanoid.Health > 0 and DB == true then
			DB = false
			Humanoid.Health = 0
			
			task.wait(1)
			
			DB = true
		end
	end)
end

function GetObjects()
	local Descendants = Folder:GetDescendants()
	
	for i, v in Descendants do
		if not table.find(Filter, v) then
			
			if v:IsA("BasePart") then
				GetHumanoid(v)
			else
				table.insert(Filter, v)
				task.wait()
				GetObjects()
			end
		end
	end
end

GetObjects()
1 Like

This works! Omg! Thanks so much! But, I’ll test it out more before I mark it as a solution

1 Like

Glad I could help! :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.