generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Touched and Touched ended really are sensitive

Previous Thread :: Next Thread 
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
18 Aug 2015 06:20 PM
Not even my debounces can tame this beast. Any solution?
--fyi this happened when i was just going in circles on the brick.

local players = {}
local num = script.Parent.Num
local debounce = false
local debounce2 = false

script.Parent.Touched:connect(function(hit)
local human = hit.Parent:FindFirstChild("Humanoid")
if not human then return end
local player = game.Players:GetPlayerFromCharacter(human.Parent)
if not player then return end
print("Touched")
if not debounce then
debounce = true
if #players > 0 then
for i,v in next, players do
if player.Name ~= v then
table.insert(players,player.Name)
num.Value = num.Value + 1
print(num.Value)
end
end
else
table.insert(players,player.Name)
num.Value = num.Value + 1
print(num.Value)
end
debounce = false
end
end)

script.Parent.TouchEnded:connect(function(hit)
local human = hit.Parent:FindFirstChild("Humanoid")
if not human then return end
local player = game.Players:GetPlayerFromCharacter(human.Parent)
if not player then return end
print("Touched ended")
if not debounce2 then
debounce2 = true
if #players > 0 then
for i,v in next, players do
if player.Name == v then
table.remove(players,i)
num.Value = num.Value - 1
print(num.Value)
end
end
end
debounce2 = false
end
end)

Output:

Touched
Touched ended
0
Touched
1
Touched ended
0
Touched
1
Touched ended
0
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
18 Aug 2015 09:12 PM
bump
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
18 Aug 2015 09:23 PM
bump
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
18 Aug 2015 10:00 PM
any1
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
19 Aug 2015 01:05 PM
shouldnt be too hard. im sure its something simple im missing just cant see it
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
19 Aug 2015 01:10 PM
qq
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
19 Aug 2015 01:23 PM
k
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
19 Aug 2015 01:56 PM
yooo
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
19 Aug 2015 05:30 PM
help
Report Abuse
unwarranted is not online. unwarranted
Joined: 05 Jun 2009
Total Posts: 1087
19 Aug 2015 05:35 PM
add a wait..?
Report Abuse
DeveloperBlue is not online. DeveloperBlue
Joined: 15 Apr 2009
Total Posts: 1344
19 Aug 2015 05:42 PM
end
wait()
debounce = false

The same for debounce2

Although, i'd recommend using wait(.4) or something
Report Abuse
lostend is not online. lostend
Joined: 21 Aug 2011
Total Posts: 8265
19 Aug 2015 05:52 PM
try this. made it on mobile and idk if it works. you will have to edit it

local players={}

function getPlr(text)
return game.Players:FindFirstChild(text)
end

function isPlr(h)
if h.Parent:FindFirstChild'Humanoid' then
return game.Players:FindFirstChild(h.Parent.Name)~=nil
end
end

script.Parent.Touched:connect(function(h)
if isPlr(h) then
if not players[h.Parent.Name] then
players[h.Parent.Name]=getPlr(h.Parent.Name)
end
end
script.Parent.TouchEnded:connect(function(h)
if isPlr(h) then
if players[h.Parent.Name] then
players[h.Parent.Name]=getPlr(h.Parent.Name)
end
end
end)
end)
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
19 Aug 2015 06:12 PM
I guess I didn't clarify the problem. The TouchEnded fires even when im still standing on the brick. How do I prevent this? It doesn't make sense that it will fire when im still on the brick but walking at the same time.
Report Abuse
PRESTIGIOUSaLEGEND is not online. PRESTIGIOUSaLEGEND
Joined: 16 Apr 2011
Total Posts: 1765
19 Aug 2015 06:23 PM
You want the Touched event to fire only on 1st contact and TouchEnded to fire on final contact.

table = {} -- this table is seperate from the one you are already using

function touched(x)
if x belongs to a character then
if character is not in table then
add character to table
do your stuff
end
end
end

function touchended(x)
if x belongs to a character then
if character is in table then
remove character from table
do your stuff
end
end
end
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
19 Aug 2015 07:49 PM
I must be an idiot but I don't see how that is any different then what I did previously and insert the player into the table to prevent the function from running again. But the TouchEnded thinks that the player stops touching the part even when he is still standing on the brick. Like wtf ._.
Report Abuse
71428 is not online. 71428
Joined: 06 Aug 2015
Total Posts: 339
19 Aug 2015 07:50 PM
Check the magnitude between the player and the brick along a 2D plane on the X and Z axis.
Report Abuse
71428 is not online. 71428
Joined: 06 Aug 2015
Total Posts: 339
19 Aug 2015 07:53 PM
And TouchEnded gets called constantly because the player is standing on the brick. If you turn CanCollide off and walk through a brick bigger than the player, TouchEnded only gets called when the player leaves the brick zone, say his arm leaves but he remains in the brick it still gets called.
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
19 Aug 2015 07:57 PM
So wrong. TouchEnded fires because of the walking and idle animations.

The only solid way to check if you are still on the brick is to raycast down from the torso when TouchEnded fires and check.
Report Abuse
71428 is not online. 71428
Joined: 06 Aug 2015
Total Posts: 339
19 Aug 2015 08:00 PM
Never knew that. Good to know.
Report Abuse
lordrambo is not online. lordrambo
Joined: 16 Jun 2009
Total Posts: 20628
19 Aug 2015 08:03 PM
well it turns out touched/touchended are touchy, go figure

raycasting and magnitude are awful solutions, check if position is within bounds of the part. ex of right of part: part.X + part.Size.X/2 = right, subtract for left, use Z for top/bottom

I'd still use touched/touchended but put the code above into touchended
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
19 Aug 2015 08:03 PM
@71428 Disabled the CanCollide and now it works thanks to you. Such a simple solution, I don't know why it took so long for someone to figure it out...but to me thats just a small hack. I still want to solve this problem even when the CanCollide is on instead of resorting to magnitude.
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
19 Aug 2015 08:05 PM
@chimmihc Would I have the brick create the raycast and check the players parts or raycast from the torso down to the brick? Woudln't this require remote events?
Report Abuse
lordrambo is not online. lordrambo
Joined: 16 Jun 2009
Total Posts: 20628
19 Aug 2015 08:06 PM
*magnitude ONLY works if the part is circular, and it must be done on a two dimensional level
*raycasting is way too computationally expensive to be reasonable
*touched/touchended doesn't work too well
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
19 Aug 2015 08:09 PM
So I guess the solution after all of this is just to stay with keeping the CanCollide off? Well, until roblox gets a better system for this (one of the most basic fundamentals of this game (A brick building game)) im going to cry in a corner.
Report Abuse
lordrambo is not online. lordrambo
Joined: 16 Jun 2009
Total Posts: 20628
19 Aug 2015 08:10 PM
yeah touchended is pretty much useless as it can't fulfill it's one purpose
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image