Updating TextLabel based on player inside a non-collidable part

I want the script to update the text label with the player’s Display Name when they’re standing in a part with CanCollide turned off.

I have tried to edit the code to try and work with this, but it doesn’t seem to work

I would appreciate it if someone could point me in the right direction for solving this. Thank you

The working code when CanCollide is turned ON for the part

local screenCover = script.Parent.Parent
local djLabel = script.Parent
local djBooth = workspace:FindFirstChild("DJBooth")

while true do
	local touchingParts = djBooth:GetTouchingParts()
	local player = nil
	for _, part in ipairs(touchingParts) do
		local parent = part.Parent
		if parent and parent:IsA("Model") and parent:FindFirstChild("Humanoid") then
			player = game:GetService("Players"):GetPlayerFromCharacter(parent)
			break
		end
	end

	if player then
		djLabel.Text = "DJ: "..player.DisplayName
	else
		djLabel.Text = "AutoDJ"
	end

	wait(0.5)
end

GetTouchingParts() Only works if CanCollide is on.

This can be remedied by using GetPartsInPart, a method of WorldRoot

workspace:GetPartsInPart(Part)

It returns an array of every part that is inside of the part you specified, you can loop through the array and see if the part belongs to a player

GetPartsInPart()

2 Likes

That has worked a charm, thank you. I will bare the GetPartsInPart documents in mind if I come across anything similar in the future. You’re a legend.

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