So basically the touch event fires every frame as long as I am within the part with the TouchInterest.
I want to know the explanation for this behaviour
My code: -LocalScript-
local function isPlayer(Hit)
local Character = Hit.Parent
if Players:GetPlayerFromCharacter(Character) == Player and Hit.Name == "Head" then
return true
end
end
Part.Touched:Connect(function(Hit)
if isPlayer(Hit) then
print("true")
end
end)
try this instead:
if it works, i’d appreciate a solution
local function isPlayer(Hit)
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
if Hit:IsDescendantOf(Character) then
return true
end
end
Part.Touched:Connect(function(Hit)
if isPlayer(Hit) then
print("true")
end
end)
You can add a debounce for triggering the .Touched event such that:
local function isPlayer(Hit)
local Character = Hit.Parent
if Players:GetPlayerFromCharacter(Character) == Player and Hit.Name == "Head" then
return true
end
end
local debounce = false
Part.Touched:Connect(function(Hit)
if debounce then return end
debounce = true
if isPlayer(Hit) then
print("true")
end
task.wait(3) --Change the number to however much you want
debounce = false
end)
In my use case this does not work, as I will be using a TouchEnded also
I know a lot of other ways to accomplish what I want, but that is not why I am here. I want to know WHY it fires every single frame aslong as I am within the part. This behaviour has never happend before when using touch events on the server.