|
| 09 Oct 2017 09:46 PM |
I'm trying to call a function every time the torso changes its position. What i'm trying to do is fire a function every time a player gets a certain distance with a given position. Is there a better way to do this rather than checking when the torso is changing position and getting a certain distance from an object? I need help because it's not firing when the position was changing but if you know a better way to do this then please tell me.
Meme Lord Muffin |
|
|
| Report Abuse |
|
|
Kailarty
|
  |
| Joined: 22 Aug 2017 |
| Total Posts: 114 |
|
|
| 09 Oct 2017 09:54 PM |
like this
if game.Players.LocalPlayer.Character.Torso.Color then Insert Function here end
I think...
Kailarty | Robux 0 | Looking For Building Job | Discord Tag: o ) LФЯD DΞΓЯДGФИΞ ( o#4306 |
|
|
| Report Abuse |
|
|
Furadious
|
  |
| Joined: 23 Dec 2013 |
| Total Posts: 601 |
|
|
| 09 Oct 2017 09:57 PM |
Use .Magnitude Something like this is probably what you're looking for?
x = game.Workspace.part y = game.Workspace.yourcharacter.Head
while wait(0.5) do
if (x.Position - y.Position).Magnitude <= 30 then print(tostring(x).." is close") -- So here you can trigger your whatever function functionName()
else print(tostring(x).." is far")
end
end
|
|
|
| Report Abuse |
|
|
EvanHolt
|
  |
| Joined: 06 Sep 2008 |
| Total Posts: 1264 |
|
|
| 09 Oct 2017 09:57 PM |
Rather than using the Changed event, have you tried using GetPropertyChangedSignal? wiki.roblox.com/index.php?title=API:Class/Instance/GetPropertyChangedSignal
[ After this tub and the next tub, there're only two tubs left! ] |
|
|
| Report Abuse |
|
|
Furadious
|
  |
| Joined: 23 Dec 2013 |
| Total Posts: 601 |
|
|
| 09 Oct 2017 09:58 PM |
| Oh whoops it was exactly what you didn't want. My bad. |
|
|
| Report Abuse |
|
|
|
| 09 Oct 2017 10:08 PM |
| it was pretty close :P Alright so my script only fires when the player joins. it fires # times so here's my code you can look at :/ game. Players.Local Player.Character: Find ##### Child("Head"):Get Property Changed Signal("Position"): Connect( function () print ("pos Changed") end) spaces just because of roblox's love for hash tags Meme Lord Muffin |
|
|
| Report Abuse |
|
|
| |
|
| |
|
Hazania
|
  |
| Joined: 04 Jun 2010 |
| Total Posts: 1344 |
|
|
| 10 Oct 2017 01:13 AM |
| What? It only fires when the player spawns? That's odd. I could see it only working until the character dies, at which point you may need to update the character, but otherwise I am not sure why it would only fire once. |
|
|
| Report Abuse |
|
|
|
| 10 Oct 2017 05:02 PM |
I think it may be due to the welding but i'm not sure???? But what i'm trying to do is make an object and if you get close enough to it it will tween a surface gui. I tried using a touched function on a part but that didn't work as the tween would just move back when the character ends there "touching session" with the part. After that I asked the forums. Now i'm thinking about making an object that needs to be touched and if another object is touched it will tween the UI back to it's normal position
Meme Lord Muffin |
|
|
| Report Abuse |
|
|
Hazania
|
  |
| Joined: 04 Jun 2010 |
| Total Posts: 1344 |
|
|
| 10 Oct 2017 05:04 PM |
I actually am encountering my own issue with this today. It will fire something like 5 times and then quit, sometimes it doesn't fire at all.
My understanding is that we shouldn't bother using Changed with positions.
|
|
|
| Report Abuse |
|
|
|
| 10 Oct 2017 05:36 PM |
ya i'd rather do ray casting or just make a part that tweens the UI forward and then another part that tweens it out. But i'm kind of new to ray casting so could somebody explain how I could find how close the torso is to the part(with rays)? But like not a loop that will cause lag just like if the ray detects something it will tween the UI but if it doesn't then it won't
Meme Lord Muffin |
|
|
| Report Abuse |
|
|
Hazania
|
  |
| Joined: 04 Jun 2010 |
| Total Posts: 1344 |
|
|
| 10 Oct 2017 06:24 PM |
For finding the distance between two parts, why use a ray?
Why not use, as mentioned above;
part = workspace.part hrp = chr.HumanoidRootPart
-- fix above directories for your game
distanceBetweenParts = (part.Position - hrp.Position).magnitude
|
|
|
| Report Abuse |
|
|
|
| 10 Oct 2017 07:28 PM |
How would i make that run over and over without using some sort of loop? like I just want to cast a ray that is around the object and if your character comes in that radius at any point(not using a loop) then it will fire a function like for example: if player find is touching this ray then fire this function. While still not using a ray just a function I believe is find part on ray?
Meme Lord Muffin |
|
|
| Report Abuse |
|
|
Hazania
|
  |
| Joined: 04 Jun 2010 |
| Total Posts: 1344 |
|
|
| 10 Oct 2017 08:36 PM |
| Use renderstepped or heartbeat for it to check every frame, or use a loop as you said, but that method is pretty meh. |
|
|
| Report Abuse |
|
|
|
| 10 Oct 2017 09:34 PM |
I just used my method and it works out fine!
Meme Lord Muffin |
|
|
| Report Abuse |
|
|