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: Find Players position relative to an object?

Previous Thread :: Next Thread 
Krosskode is not online. Krosskode
Joined: 26 Aug 2010
Total Posts: 11001
17 Dec 2014 04:02 PM
I've been working on my Single Player Adventure game kit, and my current system requires invisible bricks to be stepped on to show the door the open door Gui. It would be, in terms, better to find the players position relative to the object, rather than the invisible brick. I've look it up and found no methods for it. I know Path-finding can be done, but I've struggled to learn it. Would Path-finding be the easiest way to do it, and should I use it for the door Guis? Because, it'd also be a shame if I needed invisible bricks to pick up items, too. What do you think? Would it be easier, or is there another method.
Report Abuse
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
17 Dec 2014 04:09 PM
http://wiki.roblox.com/index.php?title=Magnitude

Relative = (player.Character.Torso.Position - object).magnitude

fill out the () with the correct st00f
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
17 Dec 2014 04:11 PM
If you mean to find a player's local space position to a part, use toObjectSpace or something.
Report Abuse
Krosskode is not online. Krosskode
Joined: 26 Aug 2010
Total Posts: 11001
17 Dec 2014 04:11 PM
I again state that I must be blind - thanks!
Report Abuse
Krosskode is not online. Krosskode
Joined: 26 Aug 2010
Total Posts: 11001
17 Dec 2014 04:25 PM
Hm, can someone give me an example? I made a simple script for this - what am I doing wrong?

local event = game.ReplicatedStorage.OpenDoors

game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(character)
local Distance = (character.Torso.Position - game.Workspace.Doors.Door1.Position).magnitude
if Distance.magnitude <= 10 then
event:FireClient(player, "Door", 2)
end
end)
end)
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
17 Dec 2014 04:35 PM
local Distance = (character.Torso.Position - game.Workspace.Doors.Door1.Position).magnitude
if Distance.magnitude <= 10 then

You mean, just Distance.
Because you just tried to find the magnitude of a number value.
Report Abuse
Krosskode is not online. Krosskode
Joined: 26 Aug 2010
Total Posts: 11001
17 Dec 2014 04:42 PM
Well, it still doesn't work, even when I touch the door.
Report Abuse
Krosskode is not online. Krosskode
Joined: 26 Aug 2010
Total Posts: 11001
17 Dec 2014 04:43 PM
Current Script:

local event = game.ReplicatedStorage.OpenDoors

game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(character)
local Distance = (character.Torso.Position - game.Workspace.Doors.Door2.Position).magnitude
if Distance <= 10 then
event:FireClient(player, "Door", 2)
end
end)
end)
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
17 Dec 2014 04:47 PM
Only checks once (When the character is added)
Report Abuse
Krosskode is not online. Krosskode
Joined: 26 Aug 2010
Total Posts: 11001
17 Dec 2014 04:48 PM
I'm stupid. Thanks for explaining this. :P
Report Abuse
Krosskode is not online. Krosskode
Joined: 26 Aug 2010
Total Posts: 11001
17 Dec 2014 04:50 PM
I added a While True Do to it and it still doesn't work.

local event = game.ReplicatedStorage.OpenDoors

game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(character)
local Distance = (character.Torso.Position - game.Workspace.Doors.Door2.Position).magnitude
while true do
wait(1)
if Distance <= 10 then
event:FireClient(player, "Door", 2)
end
end
end)
end)
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
17 Dec 2014 04:53 PM
You only calculated Distance once (When the character was added)
Report Abuse
Krosskode is not online. Krosskode
Joined: 26 Aug 2010
Total Posts: 11001
17 Dec 2014 04:58 PM
Thanks, I really do feel stupid now.
Report Abuse
Krosskode is not online. Krosskode
Joined: 26 Aug 2010
Total Posts: 11001
17 Dec 2014 05:08 PM
Well, now that I got that working, I don't want to sound too needy, but is it possible to have one script like that for every door? I currently use a remove event and a number unique to the door as you can see, and the Doors are located in a model in the workspace - is this possible?
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
17 Dec 2014 05:15 PM
I'm not convinced about how your scripting model works, but yes you can.
Report Abuse
Krosskode is not online. Krosskode
Joined: 26 Aug 2010
Total Posts: 11001
17 Dec 2014 05:17 PM
So, I'll explain it:

I have it fire an event : event:FireClient(player, "Door", 2)

There's a Gui in the Player w/ a LocalScript :
Event = game.ReplicatedStorage.OpenDoors

Event.OnClientEvent:connect(function(...)
local tuple = {...}
if tuple[1] == "Door" then
script.Parent.DoorValue.Value = tonumber(tuple[2])
if script.Parent.Label.Visible == false then
script.Parent.Label.Visible = true
end
elseif tuple[1] == "DoorStop" then
script.Parent.DoorValue.Value = 0
script.Parent.Label.Visible = false
end
end)

Then, inside the label is:

local Player = game.Players.LocalPlayer

local Event = game.ReplicatedStorage.OpenDoors

local GUI = script.Parent.Parent

local DoorVal = GUI:WaitForChild("DoorValue")

local Mouse = Player:GetMouse()

function KeyPressed()
if script.Parent.Visible == true then
Event:FireServer("OpenDoor",DoorVal.Value)
else
wait(1)
end
end

Mouse.keyDown:connect(function(key)
if key == "e" then
KeyPressed()
end
end)

Then, in the Door itself is a script:

Event.OnServerEvent:connect(function(Player, ...)
if Player then
local tuple = {...}
if tuple[1] == "OpenDoor" then
local givenDoorVal = tonumber(tuple[2])
if givenDoorVal == DoorVal.Value then
MoveDoor()
end
end
end
end)

MoveDoor does work, and, yeah.

It's pretty messy, but it's the only method I've found to work.
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
17 Dec 2014 05:26 PM
I think you need to go take a lesson on modularity because what did I just read
Report Abuse
Krosskode is not online. Krosskode
Joined: 26 Aug 2010
Total Posts: 11001
17 Dec 2014 05:28 PM
you just read something that i made in like 15 minutes
ok
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
17 Dec 2014 05:31 PM
I don't know, really. It's down to you because I still have no idea what you're doing.
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