Fixing a issue with a system that detects when a player is in a space

You can write your topic however you want, but you need to answer these questions:

  1. I want to make a script that sends a event when a player speaks and is in the room

  2. What is the issue?

i got pictures


i’m using a really nice person on the forums solution (How do I accurately check if a player is in a certain area? - #2 by GoldyyDev)

  1. What solutions have you tried so far?
more stuff yay!

I’ve tried using for i, v in pairs(blah:findtouchingparts()).

This is a “followup” to my last question that wasn’t actualy a issue lol

Full code
local Part = script.Parent.TalkSense
Part.Touched:Connect(function() end) -- Just for a TouchInterest to occur on a CanCollide false part

function CheckIfPlayerIsInArea(Part,Character)
    local touching = Part:GetTouchingParts()
	for i=1,#touching do
		if touching[i] == Character.HumanoidRootPart then
			return true
		end
	end
	return false
end
script.coolok.Event:Connect(function(data)
	if data[1] == "Request" then
		local request = CheckIfPlayerIsInArea()
		if request == true then
		script.coolok:Fire({"Return",true})
		else
			script.coolok:Fire({"Return",false})
		end
	end
end)
1 Like

Based on the error, script.Parent.TalkSense doesn’t exist. Try doing script.Parent:WaitForChild("TalkSense") instead.

Same issue :thinking: I think it’s detecting other parts and not being able to find the humanoid root part.

This is the brick

Are there any other scripts that are deleting the part as the code runs?

There shouldn’t be any since it’s supposed to always be there.

have you considered using FindPartsInRegion3?

1 Like

No. As it’s designed to detect parts rather than anything like players. It would also make it a hassle to move this thing around.

Is the part anchored? If it is and its still not working @johnnygadget’s reply might work.

Yes, It is anchored. I really don’t know why it’s doing this.

New issue, Fixed the first one by removing the function and enclosing it in the event.


image

based on these two lines of code:

You are forgetting to pass the variable’s Part & Character, which is why it cannot index the HumanoidRootPart, it doesn’t have the character!

local Part = script.Parent:WaitForChild("TalkSense")
Part.Touched:Connect(function() end) -- Just for a TouchInterest to occur on a CanCollide false part
script.coolok.Event:Connect(function(data,Character)
	if data[1] == "Request" then
	local touching = Part:GetTouchingParts()
	for i=1,#touching do
		if touching[i] == Character.HumanoidRootPart then
			script.coolok:Fire({"Return",true})
		end
	end
    script.coolok:Fire({"Return",false})
	end
end)

code is slightly different now. don’t exactly know what i’d change to allow this lol

i don’t think this line is correct either

This callback is fine. All you are doing is creating an ‘anonymous’ function inside of the callback argument instead of declaring a function and then passing the reference.