I have been making a system for teleporting players that relies on touched events, however I have run into a problem that only happens sometimes. Basically, if a player touches the part, they get teleported away. (The part is anchored; however, I don’t think that is the problem as I will later explain) Whenever I test touching the part with my main account, I get teleported almost instantly away. When My friends touch it, they get teleported also. The problem is that when my friends or one of my testing accounts jump repeatedly on the part, the part does not register the touch. It still does for my main account, but not for my friends or my alt. Here is my script that detects the touch:
-- Using @sleitnick's Component and Option Class
self.Instance.Touched:Connect(function(hit)
GetPlayerFromPart(hit):Match{
Some = function(player)
local Humanoid = player.Character:FindFirstChildOfClass("Humanoid")
if Humanoid.Health > 0 then
player.Character.HumanoidRootPart.CFrame = workspace.SpawnLocation.CFrame * CFrame.new(0,1,0)
end
end;
None = function() end
}
end)
I can send videos if needed, but they will be bad quality… and I cannot figure out how to make it not the only downloadable kind.
Setting the part to can collide just makes it so that the player can fall through the part, causing tons and tons of connections. This is not something that is wanted, and the part needs to be can collide for my game. Though it technically works, it is not preferable.
I have added a debounce, but like I said, the problem is that the event is not firing for some reason, and turning the part to CanCollide false will not work that well for my game.
You can’t rely on touched events from collision-enabled parts. Inherently, the physics means that any touch event you do receive is pretty just a discrepancy in the collision physics. You should put your ‘trigger’ part (the part with no collision and the touched event) somewhere where the player will walk through or into. Usually this part can have invisibility, and for your case, @SharpSerious’s solution is what you’re looking for. A debouce will still be required if you only want the event to fire once for the player.
Hard to tell, were they wearing packages or something you weren’t? In general it’s very unreliable, but the right practice is to always have it be no collide to ensure they’re really getting that touched event to fire.
@AstonAceMan explained it better than me. Hopefully you get the gist.
When your character is jumping when holding jump sometimes they don’t actually touch the ground*. When you make it non-collide it fixes this by making the character move further down.
* The jump is queued when the character is in the air, so the instant the controller’s raycast hits the ground the controller jumps. There are two reasons this might happen. One, the fall animation doesn’t have the foot parts that close to the ground, so when it switches to the jumping animation it moves them back up before they touch the ground. Or, alternatively, when the character is replicating it’s interpolated in-between the two positions, so on the server it doesn’t technically hit the ground. I’m not sure if this is the case though, since maybe the program sends the hits from the client if any of the parts in the hit aren’t set to server network ownership.
I have a wrench, and I am using a .Touched event to check if it hits a wall, and if it does, it will repair it. However, it doesn’t work. The wall has to have CanCollide on, how do I fix this?
You should try to do as the solution says, as it worked for me. Just make an invisible part that is a little larger than the wall, so that has more space in front. Then turn can collide off for the larger part.