One thing I would love to see with touched events is a way to detect a player touching a brick welded to them. This is something which is not currently possible and I have had to resort to using GLUE, (I know glue) to glue a brick on top of the welded brick which I am attempting to detect hits from. I would be very grateful should Roblox come up with an alternative to the touched event though I don’t see it coming any time soon. Something I would also like to see is a way to measure a touched events position from said X,Z on a brick
TouchEnded is an event?
Well it doesn’t exactly make sense as a function
Well, I didn’t know that you could check for when it ended. Just when it touched.
If you attempt to make a pad of some sort using Touched and TouchEnded, its practically impossible no matter how many debounces or whatnot you add from what Ive seen with my own attempts in the past
Yeah. I wish it wouldn’t count as touched EVERY time the player moves in the part.
I find that even if a part is sitting still inside of an object, it keeps touching untouching touching untouching etc.
It’s definitely a pain.
There are ways to prevent this, again if the player makes contact with it once, make it a local script with a statement:
--example script
script.Parent.Touched:Connect(function(hit)
local human = hit.Parent:FindFirstChild("Humanoid")
if human ~= nil then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
plr:Destroy() -- just an example
wait(.2)
script.Disabled = true --where it goes down, disables the script causing it not to go more than once
end
end
end)
Lets say we need to detect a player stepping off as well? Using this method we would be stuck in an endless loop of touched and touch ended loops as the scripts are enabled and disabled or am I thinking improperly? Local scripts would also require devs to use remotes which could also bring up security issues since whenever I am hooking up a touched event it serves a server purpose
You are thinking improperly, as when it is touched ONCE it will turn off the script automatically unless you add a statement of how it will re-enable the script ( most of the time ending up having to make a completely seperate script )
for example:
script.Parent.Touched:Connect(function(hit)
local human = hit.Parent:FindFirstChild("Humanoid")
if human ~= nil then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
plr:Destroy() -- just an example
print('Script is going to re-enable')
wait(.2)
local script = game.Workspace.YOURMODELNAME.YOURPARTNAME.YOURSCRIPTNAME
script.Disabled = false
end
end
end)
( had to edit it due to a problem )
Yes I understand that but thats what Im questioning, If I was to need to have the script be re-enabled to be reused by another player after the touch has ended.
If the event fires multiple times, you can simply disconnect it:
local TouchedEvent
TouchedEvent = Part.Touched:Connect(function(Hit)
if Hit and Hit.Parent then
local TouchEndedEvent
TouchEndedEvent = Part.TouchEnded:Connect(function(Hit)
TouchEndedEvent:Disconnect()
TouchedEvent:Disconnect()
--Do Stuff
end)
end
end)
You can easily just make the script a LocalScript so it happens locally, it wont be a serverside edit so others still have access to the brick!
Im not saying you have not figured out an alternative which may help people out but lets take a look at again the pad scenario with games which use pads to create a matchmaking system in games such as swords. Many have had to result to using region3 to solve this issue. Players must stand on pads to get matched with an opponent and using this would still cause issues as this is something which would be handled on the server and need to wait till the matchmaking is found and the round is over to re-allow players to register on the pads for their fights. There is no set time to wait before being able to re-enable the script unless someone would do it after the matchmaking has finished but lets say someone steps on then steps off, their hit would still be registered for .2 seconds after using your method which would work since it would be reenabled but if they are just waiting on the pad as you re-enable the touch event it would still cause issues while players are waiting.
My method would work , but the way it would re-enable is a COMPLETELY separate part. If you want I can go more in depth, like with values ect. Finding you a more efficient way. Would you like me to do this?
What Im explaining is that your method although it works is a little hacky and should not be required in order to be able to use the touch/touchended events. I understand what you are trying to say completely but its just not something we should be forced to do in order to get touched events working.
Well, if they revamp TouchEnded()
then they should also revamp Touched()
I did a quick thing that should fix the issue,
End result / how to set up:
The script in the “Touch” block;
--example script
script.Parent.Touched:Connect(function(hit)
local human = hit.Parent:FindFirstChild("Humanoid")
if human ~= nil then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if game.Workspace.components.IsDisabled.Value == false then
print('Roblox is the best! I like to code')
wait(.2)
game.Workspace.components.IsTouched.Value = true
game.Workspace.components.IsTouched.Value = false
script.Disabled = true
wait(.1)
end
end
end)
The “controller” script;
while true do
local disabled = game.Workspace.components.IsDisabled
local touched = game.Workspace.components.IsTouched
if disabled == true then
wait(4) --the time you want it to take for the player to be able to touch the brick again
local scripto = game.Workspace.components.touch.Script
scripto.Disabled = false
wait(.2)
disabled.Value = false
touched.Value = false
else
if touched.Value == true then
disabled.Value = true
print('disabled')
end
end
end
while true do
local disabled = game.Workspace.components.IsDisabled
local touched = game.Workspace.components.IsTouched
if touched.Value == true then
disabled.Value = true
print('disabled?')
end
end
Requirements:
-
Have a folder named “components”
-
Have the scripts I showed set up properly like in the image
-
Have 2 BoolValues , one named “IsTouched”, other named “IsDisabled”
That’s pretty much all! But you can make this WAY more advanced if you wanted to, this is just the liquefied version ( meaning simpler to understand ).
This just comes to show, there is solutions to everything!
You don’t need boolvalues, you can just make a bool variable in the script itself.
Also you should try to avoid enabling / disabling scripts.