Help With Entering A Part

I am making a script that adds the player to a folder if they enter a part called Zone.

Problem: Player is not going to folder when entering zone

Code:

local InfoService = require(game.ServerScriptService.Core.InfoService)

local function onTouched(part)
	if part:IsA("BasePart") and part.Name == "Zone" then
		local character = part
		local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
		if character:IsA("Model") and humanoidRootPart and InfoService.playerFolder then
			if InfoService.playerFolder:IsA("Folder") then
				character.Parent = InfoService.playerFolder
			else
				warn("Attempted to parent to an invalid folder.")
			end
		end
	end
end

local function onTouchEnded(part)
	local character = part
	if character:IsA("Model") and InfoService.byPlayerFolder then
		if InfoService.byPlayerFolder:IsA("Folder") then
			character.Parent = InfoService.byPlayerFolder
		else
			warn("Attempted to parent to an invalid folder.")
		end
	end
end

game.Players.PlayerAdded:Connect(function(player)
	local character = player.Character or player.CharacterAdded:Wait()
	local humanoidRootPart = character:WaitForChild("HumanoidRootPart")

	humanoidRootPart.Touched:Connect(onTouched)
	humanoidRootPart.TouchEnded:Connect(onTouchEnded)
end)
2 Likes

Try detecting the Touch and TouchEnded on the Zone part itself and then determine whether the touched part is a descendant of a player’s character.

1 Like

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