|
| 25 Nov 2016 05:44 AM |
| I want only the messages made by the players within an X radius of you to show in your chat, I know to use magnitude on this but how exactly? |
|
|
| Report Abuse |
|
|
|
| 25 Nov 2016 05:59 AM |
| Wow your avatar is so cool |
|
|
| Report Abuse |
|
|
|
| 25 Nov 2016 09:35 AM |
for i,v in pairs(game.Players:GetPlayers()) do if (PLAYER_WHO_CHATTED.Character.Torso.Position - v.Character.Torso.Position).magnitude < 100 then --Do Stuff Here end
|
|
|
| Report Abuse |
|
|
Rerumu
|
  |
| Joined: 11 Oct 2014 |
| Total Posts: 950 |
|
|
| 25 Nov 2016 09:54 AM |
Stop. That is wrong in so many ways. |
|
|
| Report Abuse |
|
|
Ryuzoji
|
  |
| Joined: 21 Dec 2015 |
| Total Posts: 937 |
|
|
| 25 Nov 2016 09:59 AM |
Erm so a chat log based on how near you are with another player? Just use magnitude.
local Radius = 50
for _, v in pairs(game.Players:GetPlayers()) do if (Speaker.Torso.Position - v.Torso.Position).magnitude <= Radius then -- Do something that allows players to see the message end end |
|
|
| Report Abuse |
|
|
|
| 25 Nov 2016 10:08 AM |
| ####### Says its wrong but doesnt say why nor give better more effective code |
|
|
| Report Abuse |
|
|
Rerumu
|
  |
| Joined: 11 Oct 2014 |
| Total Posts: 950 |
|
|
| 25 Nov 2016 10:10 AM |
-- You're making me suffer.
local Me = (myplayer.Character or myplayer.CharacterAdded:wait()):WaitForChild('Torso'); local X = 50 -- Distance.
-- When receiving...
for _, User in ipairs(game:GetService('Players'):GetPlayers()) do local Char = User.Character; if Char and ((((Char:FindFirstChild('Torso') and Char.Torso.Position) or Me.Position) - Me.Position).magnitude <= X then -- Receive. end end |
|
|
| Report Abuse |
|
|
Rerumu
|
  |
| Joined: 11 Oct 2014 |
| Total Posts: 950 |
|
|
| 25 Nov 2016 10:12 AM |
@supreme
Missing an end. Using "pairs" for an array. Not checking if the player has a character. Not checking if the character has a torso. |
|
|
| Report Abuse |
|
|
Ryuzoji
|
  |
| Joined: 21 Dec 2015 |
| Total Posts: 937 |
|
|
| 25 Nov 2016 10:13 AM |
| ####### He only pointed out the basic structure on how to use it. Of course, there will be errors with the code. You basically did the same exact thing, only thing you added new was actual variables and actually waiting for the character. Jesus, so many cancerous people these days. |
|
|
| Report Abuse |
|
|
Rerumu
|
  |
| Joined: 11 Oct 2014 |
| Total Posts: 950 |
|
|
| 25 Nov 2016 10:15 AM |
| It's not cancerous to invalidate misinformation, especially when it would error before even running. |
|
|
| Report Abuse |
|
|
Ryuzoji
|
  |
| Joined: 21 Dec 2015 |
| Total Posts: 937 |
|
|
| 25 Nov 2016 10:17 AM |
"Missing an end." "He only pointed out the basic structure on how to use it."
"Using "pairs" for an array." They both work either way.
"Not checking if the player has a character." Are you serious? Of course it has a character. The only case this it would not if it falls out the map or something.
"Not checking if the character has a torso." ^ Jesus, you don't have to be so cancerous.
Again, "He only pointed out the basic structure on how to use it." |
|
|
| Report Abuse |
|
|
Rerumu
|
  |
| Joined: 11 Oct 2014 |
| Total Posts: 950 |
|
|
| 25 Nov 2016 10:20 AM |
Players don't have a character until they respawn after they die. Characters without a torso or no character errors instantly. You can't compile something with a syntax error. Using pairs on arrays is much slower, not to mention useless key lookups where there are none.
Are you trolling or just plain stupid? |
|
|
| Report Abuse |
|
|
Ryuzoji
|
  |
| Joined: 21 Dec 2015 |
| Total Posts: 937 |
|
|
| 25 Nov 2016 10:24 AM |
Read what I said again.
I said using pairs and ipairs would work either way. Never said ipairs was bad. And again, I told you, we are just showing the basic outline on how to use magnitude to detect players in a 100 studs radius. |
|
|
| Report Abuse |
|
|
Ryuzoji
|
  |
| Joined: 21 Dec 2015 |
| Total Posts: 937 |
|
|
| 25 Nov 2016 10:26 AM |
| And I guess you're right about the Character. |
|
|
| Report Abuse |
|
|
Rerumu
|
  |
| Joined: 11 Oct 2014 |
| Total Posts: 950 |
|
|
| 25 Nov 2016 10:27 AM |
| You're still creating bad habits, and not really helping anyone. Pairs was not made for only arrays, people should know that so they don't start wondering why their code is slow. Same with syntax, if it ain't right they won't know what to do. |
|
|
| Report Abuse |
|
|
vastqud
|
  |
| Joined: 10 Sep 2011 |
| Total Posts: 2464 |
|
|
| 25 Nov 2016 10:28 AM |
rer, you effectively did the same thing that the other guy did, but with a few changes.
his script wasn't wrong, it just wasn't perfect. it was just the basic structure of how to do it |
|
|
| Report Abuse |
|
|