What Could Cause This Problem?

I am making a door opening system, but the touched event is only firing if I jump. What could cause this problem?

Server Script
local distanceModule = require(game.ServerScriptService.doorHandlers.getDistance)
local doorFolder = game.Workspace.castleDoors
local collectionService = game:GetService("CollectionService")

local currentTag = 1
for _, model in ipairs(doorFolder:GetChildren()) do
	collectionService:AddTag(model.Union, "doorUnions")
	currentTag += 1

for _, part in pairs(collectionService:GetTagged("doorUnions")) do
	part.Touched:Connect(function(hit: Part)
		local character = hit.Parent
		if character then
			local player = game.Players:GetPlayerFromCharacter(character)
			if not player then return end
			local result = distanceModule:getPlayerDistance(player, part)
			if result == true then
				part.CanCollide = false
Module Script
local module = {}

function module:getPlayerDistance(player: Player, doorModel)
	local playerCharacter = player.Character or player.CharacterAdded:Wait()
	if playerCharacter then
		if (Vector3.new(doorModel.CFrame.X, doorModel.CFrame.Y, doorModel.CFrame.Z) - Vector3.new(playerCharacter.HumanoidRootPart.CFrame.X,playerCharacter.HumanoidRootPart.CFrame.Y,playerCharacter.HumanoidRootPart.CFrame.Z)).Magnitude <= 3 then
			return true
			return false

return module

I’ve recorded a Medal clip, you can find it here.

Doors Location(s)

Thanks in advance!

  1. Bit nitpicky, but do not convert CFrames to Vector3s using your method, just do this. It’s faster to write and run.
if (doorModel.CFrame.Position - playerCharacter.HumanoidRootPart.CFrame.Position).Magnitude <= 3
  1. This could be caused by accessory parts colliding with the object. Try to either just change it to every heartbeat if you want it to just run it, or you can make it detect for accesories as well by doing
local player = game.Players:GetPlayerFromCharacter(character) or game.Players:GetPlayerFromCharacter(character.Parent) -- Character.Parent would be the accessory class, and the part hit would be the handle underneath.
1 Like

Oh, I forgot. I know why it didn’t fire. I had the minimum studs set to three. So when I jump I was close enough to the center of the union. But if I just walked in it I wasn’t…

Anyways, still thanks for your help!

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