Renshiro
|
  |
| Joined: 29 Aug 2014 |
| Total Posts: 12 |
|
|
| 23 Apr 2016 09:49 AM |
Hello guys, I've trying to do the 'press [e] to inspect/examine' thing whenever close to an object. Any help regarding this? Helpful efforts are very much appreciated.
Anyways, on my first try, what I did is put a localscript on startergui and... mouse.KeyDown:connect(function(key) key = key:lower() game.Workspace.Toilet.Toilet.Click.Touched:connect(function(hit) if game.Players:findFirstChild(hit.Parent.Name) and key == "e" then local hint = Instance.new("Hint",playerChar:FindFirstChild("Head")) hint.Text = script.text2.Value wait(2) hint:remove()
on a second thought, that was *very* noobish. I'm sorry.
I need help. Thank you! hope to be welcome in this forum :)
--Ren/Shiro |
|
|
| Report Abuse |
|
|
|
| 23 Apr 2016 09:50 AM |
y u use deprecated events
#Code print("Add 13,000 posts") |
|
|
| Report Abuse |
|
|
Renshiro
|
  |
| Joined: 29 Aug 2014 |
| Total Posts: 12 |
|
|
| 23 Apr 2016 09:51 AM |
Unfortunately, all my tries fail.
By the way, 'Click' is a non-CanCollide part. |
|
|
| Report Abuse |
|
|
Renshiro
|
  |
| Joined: 29 Aug 2014 |
| Total Posts: 12 |
|
|
| 23 Apr 2016 09:53 AM |
@Lord_Narwhal
I've tried scripting back in 2011, and returned to Studio recently... So I have no idea. |
|
|
| Report Abuse |
|
|
|
| 23 Apr 2016 09:54 AM |
instead of touched the object, use magnitude
if (toilet.Pos-torso.Pos) <=10
if the player presses e, you check if they're close to any examinable objects
it would be like this
local obj = {"Toilet","Door","Closet} use userinputservice to detect when player presses e, then
for i,v in pairs(obj) do
if (game.Workspace[obj].Position-game.Players.LocalPlayer.Position).magnitude <=10 then print("Player is close to object and pressed e")
#Code print("Add 13,000 posts") |
|
|
| Report Abuse |
|
|
|
| 23 Apr 2016 09:55 AM |
whoops
game.Players.LocalPlayer.Character.Torso.Position
#Code print("Add 13,000 posts") |
|
|
| Report Abuse |
|
|
Renshiro
|
  |
| Joined: 29 Aug 2014 |
| Total Posts: 12 |
|
|
| 23 Apr 2016 10:01 AM |
Thank you..
I may be confused.. Is 'position' a value?
--Ren/Shiro |
|
|
| Report Abuse |
|
|
|
| 23 Apr 2016 10:07 AM |
magnitude is just the distance
i'm using the char's torso and the inspection object to find the distance between them
#Code print("Add 13,000 posts") |
|
|
| Report Abuse |
|
|
Renshiro
|
  |
| Joined: 29 Aug 2014 |
| Total Posts: 12 |
|
|
| 23 Apr 2016 10:35 AM |
output says "bad argument #2 to '?' (string expected, got table)" on line if (game.Workspace[obj].Position-game.Players.LocalPlayer.Position).magnitude <=10 then |
|
|
| Report Abuse |
|
|
|
| 23 Apr 2016 10:38 AM |
dude you should use :toObjectSpace()for magnitude
like for example:
game.Players.LocalPlayer.Torso.CFrame:toObjectSpace(game.Workspace.Toilet).p.magnitude |
|
|
| Report Abuse |
|
|
|
| 23 Apr 2016 10:42 AM |
i've never even seen toObjectSpace
it printed nil because i forgot to do
game.Workspace[obj]
#Code print("Add 13,000 posts") |
|
|
| Report Abuse |
|
|
|
| 23 Apr 2016 10:43 AM |
OH it's not obj
derp
it's game.Workspace[v]
that felt stupid
#Code print("Add 13,000 posts") |
|
|
| Report Abuse |
|
|
|
| 23 Apr 2016 10:45 AM |
:toObjectSpace() is a CFrame method that gives the relative distance between two parts
|
|
|
| Report Abuse |
|
|
|
| 23 Apr 2016 10:45 AM |
that's so much simpler
#Code print("Add 13,000 posts") |
|
|
| Report Abuse |
|
|
|
| 23 Apr 2016 10:47 AM |
its the same as doing the subtraction.
CFrame:lerp can position a block in the middle of two other blocks if you ever wondered |
|
|
| Report Abuse |
|
|
|
| 23 Apr 2016 10:49 AM |
ever since i learned what lerp is i've been using it to cframe one part to another smoothly
it works great and also ignores parts on its path which is even more useful
#Code print("Add 13,000 posts") |
|
|
| Report Abuse |
|
|
Renshiro
|
  |
| Joined: 29 Aug 2014 |
| Total Posts: 12 |
|
|
| 23 Apr 2016 10:56 AM |
| um, what should I do next? |
|
|
| Report Abuse |
|
|
Renshiro
|
  |
| Joined: 29 Aug 2014 |
| Total Posts: 12 |
|
|
| 23 Apr 2016 10:59 AM |
"Torso is not a valid member of Player" I don't get the output. |
|
|
| Report Abuse |
|
|
Renshiro
|
  |
| Joined: 29 Aug 2014 |
| Total Posts: 12 |
|
|
| 23 Apr 2016 11:04 AM |
never mind, ^^ it should be "game.Players.LocalPlayer.Character.Torso" to find the torso
@zarman3402 I'm sorry for asking, but how should I use :toObjectSpace() ? |
|
|
| Report Abuse |
|
|
Renshiro
|
  |
| Joined: 29 Aug 2014 |
| Total Posts: 12 |
|
|
| 24 Apr 2016 05:07 AM |
How do I do this on multiple objects? Like a different print per object.
Tried to copy-paste the first object and change variables but no effect. |
|
|
| Report Abuse |
|
|
Renshiro
|
  |
| Joined: 29 Aug 2014 |
| Total Posts: 12 |
|
|
| 24 Apr 2016 05:09 AM |
I hate myself. sorry guys, problem solved. XD |
|
|
| Report Abuse |
|
|