Help With Touching Parts

This script constantly check if the player’s torso it touching a part called lobbyPart making “Act” true or false based on if the player is touching the part or not.

Problem: Nothing is printing or working. There are not errors either.

Is there a better way to do this and if not how do I fix this

--==============================================================================
--LOCAL SCRIPT >> SCRIPTS
--==============================================================================
--<<VERIABLES>>
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local torso = character:WaitForChild("HumanoidRootPart")
local lobbyPart = workspace.Map.Spawn.Spawn.Base:WaitForChild("LobbyPart")
local button = script.Parent.Parent.Buttons
--==============================================================================
--<<FUNCTIONS>>
while wait(1) do
	local partsTouched = torso:GetTouchingParts()

	for _, part in pairs(partsTouched) do
		if part == lobbyPart then
			print("Player's torso is touching lobbyPart!")
			button:WaitForChild("Act").Value = false
		else
			button:WaitForChild("Act").Value = true
		end
	end
end
--==============================================================================

You can just use the .Touched event instead of this that might help with your issue.

Thanks, but it still does not work or print anything

--==============================================================================
-- LOCAL SCRIPT >> SCRIPTS
--==============================================================================
-- <<VARIABLES>>
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local torso = character:WaitForChild("HumanoidRootPart")
local lobbyPart = workspace.Map.Spawn.Spawn.Base:WaitForChild("LobbyPart")
local button = script.Parent.Parent.Buttons
local debounce = false -- Used to prevent rapid firing of the event
--==============================================================================
-- <<FUNCTIONS>>
torso.Touched:Connect(function(hit)
	if hit:IsA("BasePart") and hit:IsDescendantOf(lobbyPart) then
		print("Player's torso is touching lobbyPart!")
		if not debounce then
			debounce = true
			button:WaitForChild("Act").Value = false
			wait(1)
			debounce = false
		end
	else
		button:WaitForChild("Act").Value = true
	end
end)
--==============================================================================

Thats because your checking for the wrong thing to be touched here is the corrected code.

----==============================================================================
-- LOCAL SCRIPT >> SCRIPTS
--==============================================================================
-- <<VARIABLES>>
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local torso = character:WaitForChild("HumanoidRootPart")
local lobbyPart = workspace.Map.Spawn.Spawn.Base:WaitForChild("LobbyPart")
local button = script.Parent.Parent.Buttons
local debounce = false -- Used to prevent rapid firing of the event
--==============================================================================
-- <<FUNCTIONS>>
lobbyPart.Touched:Connect(function(hit)
	if hit:IsA("BasePart") and hit:IsDescendantOf(lobbyPart) then
		print("Player's torso is touching lobbyPart!")
		if not debounce then
			debounce = true
			button:WaitForChild("Act").Value = false
			wait(1)
			debounce = false
		end
	else
		button:WaitForChild("Act").Value = true
	end
end)
--==============================================================================
Tip

.Touched Events are replicated to the storage so everyone will see what happens!

That problemly will work but I found the solution.

Problem: That script is searching for hit:IsDescendantOf(lobbyPart)

if hit:IsA("BasePart") and hit:IsDescendantOf(lobbyPart) then

Solution:

if hit:IsA("BasePart") and hit.name == "LobbyPart" then

But thanks for saying to use .Touched event instead it works better

1 Like

Mark the post as solved :+1:

Char Limit

aaaaaaaaaaa

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