How about script.Parent.Parent instead of script.Parent?
that’s basically parenting the script to Portal2
can you show the scale of the parts, both visually and on the properties?
One of the things that I noticed about your code is the way that it’s structured. For the server, you want to get in and out as quickly as possible. This script will do that with full error checking. This also explicitly sets certain properties of the part or part’s primary part (if a model). If this doesn’t work for you, then something else is wrong.
-- ******** Requirements
-- Required Game Services and Facilities
local playerService = game:GetService("Players")
-- ******** Local Data
local ident = script.Parent
local part
local debounce = false
local cooldown = 1.0000
-- ******** Functions/Methods
-- Determines if the given identity is a part or model.
-- If a model, then the model's primary part is returned,
-- otherwise the identity is returned as a part.
local function getPrimaryPart(ident)
-- Setup
local part = nil
-- Determine if we are dealing with a part or a model.
if ident:IsA("BasePart") or ident:IsA("UnionOperation") or
ident:IsA("MeshPart") or ident:IsA("IntersectOperation") then
part = ident
elseif ident:IsA("Model") then
if ident.PrimaryPart ~= nil then
part = ident.PrimaryPart
else
warn("Model primary part not set:", ident.Name)
end
else
warn("getPrimaryPart: Unknown identity specified:", typeof(ident), ident)
end
return part
end
-- Returns the player, character, humanoid, and humanoid root part from
-- the given item, if possible. If player == nil while the other
-- components != nil, then we are dealing with an NPC of some sort.
local function getPlayerParts(hitPart)
-- Searches up the object tree for a humanoid. This will
-- backup 5 times before giving up.
local function searchHumanoid(part)
-- Setup
local model = part
local temp
local human
for i = 1, 5, 1 do
temp = model:FindFirstAncestorOfClass("Model")
if temp ~= nil then
human = temp:FindFirstChild("Humanoid")
if human ~= nil then
return temp, human
else
model = temp
end
else
return nil, nil
end
end
end
-- Setup
local player = nil
local char = nil
local human = nil
local root = nil
-- Determine if we are dealing with a humanoid.
char, human = searchHumanoid(hitPart)
if char ~= nil and human ~= nil then
-- Model has a humanoid child. Validate other structural components.
root = char:FindFirstChild("HumanoidRootPart")
if root ~= nil then
-- We have a character, humanoid, and a humanoid root part. If
-- this returns nil, then we are dealing with an NPC.
player = playerService:GetPlayerFromCharacter(char)
else
-- Not a valid humanoid. Hacker?
return nil, nil, nil, nil
end
else
-- Not a humanoid.
return nil, nil, nil, nil
end
-- Return Results
return player, char, human, root
end
-- ******** Initialization
-- Make sure the parent is something we can deal with.
part = getPrimaryPart(ident)
if part == nil then
local msg = string.format("Invalid parent identity. Parent must be a BasePart, " ..
"UnionOperation, IntersectOperation, or Model: %s", typeof(ident)) .. ident
error(msg)
return
end
-- Set the part's properties.
part.Anchored = true
part.CanCollide = false
part.CanTouch = true
part.CanQuery = true
-- ******** Events
part.Touched:Connect(function(hitPart)
if debounce == false then
debounce = true
-- Make sure we are dealing with a character. If not, then
-- abort.
local player, char, human, root = getPlayerParts(hitPart)
if char == nil then
debounce = false
return
end
print("Hi")
-- Cooldown Timer
task.delay(cooldown, function()
debounce = false
end)
end
end)
This script has been tested on a baseplate with no errors. To use it, just place the script under a part, union, intersection, or model and it takes it from there. If you are using a model, make sure that you set a primary part for the model because the script will use that if it’s parented to a model.