What I usually do for hit detection is to check if the hit.Parent has a player, since hit.Parent can be a part of an accessory.
script.Parent.Touched:Connect(function(Object)
local player = game.Players:GetPlayerFromCharacter(Object.Parent)
if player then
local hum = player.Character:FindFirstChild("Humanoid")
if not cooldown then
cooldown = true
print("hi")
wait(1)
cooldown = false
end
end
end)
local teleportDestination = workspace.TeleportDestination
local portal = script.Parent
local cooldown = false
portal.Touched:Connect(function(hit)
local character = hit.Parent
if character:IsA("Model") and character:FindFirstChild("Humanoid") and not cooldown then
cooldown = true
print("Teleporting...")
local destinationPosition = teleportDestination.Position
character:SetPrimaryPartCFrame(CFrame.new(destinationPosition))
wait(1)
cooldown = false
end
end)
This is a case where the issue is most likely being caused by the way something is built instead of a problem with the script because I tested the script exactly as it is written in the screenshot both on a single part and in a hitbox part inside of a larger part and Touched did detect correctly (the only time it failed was when I tried making the hitbox part very small compared to the parent part). I recommend you try these steps:
Make the Script a child of Portal2 instead of the hitbox Part
Delete the hitbox part as it shouldn’t be necessary in your case
Be extra sure CanTouch is true for the Portal2 part
If you follow these steps and the function still doesn’t run then the possible problems I can think of are:
There might be other lines inside of the script where the Touched event is that’s preventing it from working since in the screenshot provided the line numbers aren’t visible so we don’t know if it’s the full code
Another script is interfering with either the Portal2 Part or the script
A plugin you have installed in Studio is interfering
If it works for the baseplate or another part which doesn’t contain particles why don’t you try to delete that particle. Or maybe I am guessing your hitbox is inside of that particle part if you are using diffrent parts for particles and hitbox.
I’ve done everything no other script could be interfering and the screenshot i had shown from the code above was the full code just like the guy under here said i think it’s most likely that the particles are the reason it’s not working properly but i do still need the particles since without them there’s no portal so I have to find a way around it
If the particles are causing the problem then it’s most likely a bug as that shouldn’t be happening
I suggest you try making the hitbox part slightly bigger than the Portal2 part and if that still doesn’t work then report this as a possible bug to Roblox
I wish you luck finding a solution to this problem. I too suspect there might be something wrong with the particles but unfortunately I’m on mobile now so I won’t be able to test the theory