Finding the HumanoidRootPart from a ClickDetector

I’m trying to make a script that checks if the place is occupied, and if it isn’t, it will teleport the player to said place. I just can’t seem to figure out how to find the player’s HumanoidRootPart. I can’t find a solution anywhere, even though it’s probably really obvious, lol. (apologies if this question seems stupid)

occupied = false -- room occupied?
local Holy = game.Workspace.Holy -- part to be teleported to
local Clicks = game.Workspace.LaLa -- part to be clicked
local Clicker = game.Workspace.LaLa.ClickDetector --part's click detector
Clicker.MouseClick:Connect(function(plr) --accessing player through click function
	if occupied == false then --room not occupied, then teleport
		local pname = plr.Name
		Holy.Transparency = .5
		--[[ need to find the Workspace version of player to put here--]].HumanoidRootPart.CFrame = CFrame.new(Vector3.new(-50.04, 6.15, -24.212)) -- teleport player to position of Holy
		occupied = true
		end
	
	if occupied == true then
			plr.PlayerGui.ScreenGui.Enabled = true --if the room is occupied, enable the gui notifying player
			wait(3)
			plr.PlayerGui.ScreenGui.Enabled = false --disable gui afterwards

	end
end)

player.Character points to the character model in workspace. Also the server should never be touching PlayerGui so you should use a remote event for showing GUIs.

2 Likes

Works perfectly! As for the GUI, it took me a while to figure out how to use a RemoteEvent, but I got it to work. Thanks a lot! :+1: