Part parameter must be BasePart

Recently i started having this issue with a script, it’s supposed to make a GUI show up while you’re in a part region

The problem is that it has started throwing the error “Part parameter must be BasePart” and i have no idea how to fix it.

image

Code:

local replicated = game:GetService("ReplicatedStorage")
local ScreenEvent = replicated.Data:WaitForChild("Screen")
local p = workspace.SleepStuff:FindFirstChild("SleepingRegion")
local gui = gamer.PlayerGui:WaitForChild("SleepWakeBtn")
local screenval = gamer.PlayerGui.ScreenBlackout:WaitForChild("CheckVal")
local votingstate = replicated.Vote.Started

local overlap = OverlapParams.new()

local found

local runservice = game:GetService("RunService")

runservice.Stepped:Connect(function()
	local t_table = workspace:GetPartsInPart(p, overlap)
		for _, part in pairs(t_table) do
			if part:IsA("BasePart") then
				found = false
				local player = game.Players:GetPlayerFromCharacter(part.Parent)
				if player and player == gamer then
					found = true            
				else
					found = false    
				end
				if found == true and replicated.Data.GameState.Value ~= "Changing" and screenval.Value == false and votingstate.Value == false then
					gui.Enabled = true
					break
				else
					gui.Enabled = false
				end
			end
		end
end)

Edit: It also happens always after the player dies.
My best guess is that it tries to execute the script when the BasePart hasn’t loaded in yet.

1 Like

Add another check before found = false where:

if part:IsA("BasePart") then
	
end
1 Like
local p = workspace.SleepStuff:FindFirstChild("SleepingRegion")

The issue is here, this is likely a reference to a model not a part.

local t_table = workspace:GetPartsInPart(p, overlap)

GetPartsInPart's first argument must be a reference to a part instance.

2 Likes

Added it and the error still occurs…

1 Like

It is an Union inside of a Folder, from what i remember unions work with that too so i don’t get the problem

1 Like

That is line 16 of the script (the same line output in the error message).

1 Like

I don’t get what you mean, the P variable is a Part so it means that it is referencing to a Part instance
image

I also added the check but it doesn’t seem to be doing anything since like i’ve said the error still occurs
image

1 Like

local t_table = workspace:GetPartsInPart(p, overlap)
The issue is here, use a regular part instance for ‘p’.

1 Like