|
| 29 Dec 2015 04:12 AM |
What would you say would be the most efficient way to check someone's distance constantly to a part?
function Check(Character) if (Character.Torso.Position-Part.Position).magnitude ~= 15 then return true end end
while wait() do if Check(game.Workspace.PlayerName) then print('True') end end |
|
|
| Report Abuse |
|
|
|
| 29 Dec 2015 04:18 AM |
With an event.
local Player = game:GetService("Players").LocalPlayer local Character = Player.Character
Character.Torso.Changed:connect(function(X) if (Character.Torso.CFrame.p-Part.CFrame.p).magnitude < 15 then print'Domestic cats' end end)
--Position is too long. |
|
|
| Report Abuse |
|
|
|
| 29 Dec 2015 04:21 AM |
| I'm running it from the server to prevent exploitation, got anything for that? |
|
|
| Report Abuse |
|
|
|
| 29 Dec 2015 04:23 AM |
Here's a snippet of my current code:
local CheckTeams() local Team1 = 0 local Team2 = 0 for i,v in pairs(game.Players:GetChildren()) do if (v.Character.Torso.Position-Status.Position).magnitude ~= 15 then if v.TeamColor == game.Teams["H"].TeamColor then Team1 = Team1+1 elseif v.TeamColor == game.Teams["R"].TeamColor then Team2 = Team2+1 end end end end
while wait(1) do CheckTeams() end
|
|
|
| Report Abuse |
|
|
|
| 29 Dec 2015 04:24 AM |
Double or triple radius.
It's basically the same thing.
There should be one radius that detects the person is getting near to the part which maybe like (.magnitude < 50) which runs exactly every 5 or 10 seconds. If it detects a player then the player gets to be spammed with a wait() that checks the player's range from the part.
Don't tell me you lost it. |
|
|
| Report Abuse |
|
|
|
| 29 Dec 2015 04:37 AM |
.-.
Not really what I had in mind... I might just use a LocalScript instead and have it run an event once the player is near the part? But I don't want to stress out the player's movements. |
|
|
| Report Abuse |
|
|
Ryuzoji
|
  |
| Joined: 21 Dec 2015 |
| Total Posts: 937 |
|
|
| 29 Dec 2015 04:51 AM |
Wait...
Parts cant detect changes in positions, velocity, rotations, cframes, etc. |
|
|
| Report Abuse |
|
|
|
| 29 Dec 2015 05:21 AM |
| Well seeing that it is a property, it's possible? |
|
|
| Report Abuse |
|
|
|
| 29 Dec 2015 05:21 AM |
@Ryu Yea they do. Part.Changed:connect()
@OP stress out the player's movement? |
|
|
| Report Abuse |
|
|
|
| 29 Dec 2015 05:23 AM |
It's a fort terminal script that checks the distance of players from the terminal. If in rage it is to activate and turn to that teams item, but to do so I'm using a while wait() do end script which causes major lag, I cannot have this as players are battling.
|
|
|
| Report Abuse |
|
|
|
| 29 Dec 2015 05:24 AM |
| That's why I said, make a .magnitude<50 radius, or bigger that what you want that wait exactly 5 or more seconds. So it's not flooded. |
|
|
| Report Abuse |
|
|
|
| 29 Dec 2015 05:25 AM |
| However, if I do that aren't I just adding more problems? |
|
|
| Report Abuse |
|
|
Ryuzoji
|
  |
| Joined: 21 Dec 2015 |
| Total Posts: 937 |
|
|
| 05 Jan 2016 05:26 AM |
| You can do a loop check of it's position, but you cant detect Position, Velocity, CFrame, etc. changes. |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 05 Jan 2016 05:49 AM |
Properties changed by the physics engine will not fire the Changed event.
|
|
|
| Report Abuse |
|
|
chimmmihc
|
  |
| Joined: 24 Jul 2014 |
| Total Posts: 2420 |
|
|
| 05 Jan 2016 06:29 AM |
| Rouz and chims avatar have different lighting |
|
|
| Report Abuse |
|
|
|
| 05 Jan 2016 06:51 AM |
@chimmmihc why is your name like his name
@ImperialOutcast here, use this
-- local script
local Player = game:GetService("Players").LocalPlayer local Root = (Player.Character or Player.CharacterAdded:wait()):WaitForChild("HumanoidRootPart")
local SteppedConnection SteppedConnection = game:GetService("RunService").Stepped:connect(function() if Root then if (Root.Position-workspace.Part.Position).magnitude ~= 15 then print("True") end else SteppedConnection:disconnect() end end)
-- server script
local RunService = game:GetService("RunService")
game:GetService("Players").PlayerAdded:connect(function(Player) Player.CharacterAdded:connect(function(Character) local Root = Character:WaitForChild("HumanoidRootPart") local SteppedConnection SteppedConnection = RunService.Stepped:connect(function() if Root then if (Root.Position-workspace.Part.Position).magnitude ~= 15 then print("True") end else SteppedConnection:disconnect() end end) end) end)
|
|
|
| Report Abuse |
|
|
|
| 05 Jan 2016 07:40 AM |
| Woah, you should use a Changed event on that! Loops are to be avoided as much as possible, but a changed event would fire even more often than a loop here. When you're walking, your position changes constantly, without a pause. Dangerous stuff. |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 05 Jan 2016 07:43 AM |
"When you're walking, your position changes constantly, without a pause."
No, it will never fire from you walking.
|
|
|
| Report Abuse |
|
|
|
| 05 Jan 2016 07:45 AM |
| Ye, i just read that lol. But I do think it wasn't always like that. I know that I once crashed my game cause of such an event. And it was the only script around... With no loops e.e |
|
|
| Report Abuse |
|
|
|
| 05 Jan 2016 06:15 PM |
@HarrySnotte you cant use changed to track a position, so he HAS to use a loop
i made a thread about how a moved event should be added and nobody cared |
|
|
| Report Abuse |
|
|
Aethex
|
  |
| Joined: 16 Oct 2011 |
| Total Posts: 2193 |
|
|
| 05 Jan 2016 06:40 PM |
| wanted to mention that DistanceFromCharacter should be used instead of magnitude when checking player distance: http://wiki.roblox.com/index.php?title=API:Class/Player/DistanceFromCharacter |
|
|
| Report Abuse |
|
|
|
| 05 Jan 2016 06:42 PM |
| It's better to use neither and just make an equation for checking. |
|
|
| Report Abuse |
|
|
icanxlr8
|
  |
| Joined: 25 Feb 2009 |
| Total Posts: 3686 |
|
|
| 05 Jan 2016 06:52 PM |
plr = -- put however you access the player here part = -- put a directory to the part here while true do dis = plr:DistanceFromCharacter(part.Position) -- stuff wait() end
Rock on! http://www.roblox.com/games/121584089/Rock-Roleplay |
|
|
| Report Abuse |
|
|
|
| 05 Jan 2016 06:52 PM |
It's better to completely chuck magnitude out the window and use an official method:
while true do if game.Players.PlayerName:DistanceFromCharacter(Part.Position) then --code end wait() end |
|
|
| Report Abuse |
|
|
Aethex
|
  |
| Joined: 16 Oct 2011 |
| Total Posts: 2193 |
|
|
| 05 Jan 2016 06:57 PM |
everyone brings up DistanceFromCharacter after I mention it :(
just kidding, i don't really care, i didn't read half the posts above mine anyway |
|
|
| Report Abuse |
|
|