Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Part being Touched doesn't properly find the Player?

Hello.

I am currently trying to make a Portal only teleport the player if they've met some conditions. This does work, however, the part won't actually detect the player unless you step on the part multiple times. I'm not sure what's causing this, and it's very confusing.

My Script:

local Players = game:GetService("Players")
local Portal = workspace["Portal of Life1"]

local Died = false
local Debounce = false

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remote = ReplicatedStorage.FadeRemote

Players.PlayerAdded:Connect(function(Player)
	print("Player added")
	Player.CharacterAdded:Connect(function(Character)
		print("Character added")
		local Humanoid = Character:WaitForChild("Humanoid")
		Humanoid.Died:Connect(function()
			print("Player died")
			Died = true
		end)
	end)
end)

Portal.Core.Touched:Connect(function(ObjectCollided)
	if not (Debounce) then
		Debounce = true
		local PlayerHumanoid = ObjectCollided.Parent:FindFirstChildWhichIsA("Humanoid")
		local Player = Players:GetPlayerFromCharacter(ObjectCollided.Parent)
		if (Died and Player) then
			print("Passed step")
				ObjectCollided.Parent.Humanoid.WalkSpeed = 0
				print("Yes")
				ObjectCollided.Parent.IsTeleporting.Value = true
				Remote:FireClient(Player)
				wait(14)
				ObjectCollided.Parent.HumanoidRootPart.CFrame = CFrame.new(-566.43, -97.266, 202.748)
				wait(1)
				ObjectCollided.Parent.IsTeleporting.Value = false
		end
		wait(1)
		Debounce = false
	end
end)

I'm not sure why this happens and would like some help. Thanks!

1 answer

✓ Accepted answer

I suspect it's because of the debounce at the beginning, it activates whenever it touches a part even when the part isn't the player. Try moving the debounce bit under line 27, that way it only activates when the touched part is the player.

1 comment

0

Worked. Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.