Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would you find a player's position through a script?

Asked by 8 years ago

I know what I would (probably) use, but I don't know how I would piece it together in a script. The script is supposed to play music when the player gets within certain coordinates, and when they walk out the music stops.

I know I would use a Vector3 to get the position, but I don't know how you would make something happen between certain coordinates, and how you would put that in correlation with the other parts of the script. Below is a very general idea of how that would go.

if --Calculate the positions here
then game.Workspace.Sound:Play()

elseif game.Workspace.Sound:Stop()

As you can see, I'm very new to this and help would be very, very appreciated. Thank you in advance.

1
Sorry I don't have time to give a full drawn-out answer, but I suggest you look into Region3 (http://wiki.roblox.com/index.php?title=API:Region3) and magnitude (http://wiki.roblox.com/index.php?title=Magnitude). Whichever serves your purpose better. ScriptGuider 5640 — 8y
0
Region3 sounds more fitting as I'm trying to make the sound only play in a 20 x 20 x 10 space, hence a 3D space. If you can find time to give me more detail, that would be appreciated, but if you can't that's cool too. Thanks for the information! :) ItsTheELitist 29 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

First you would use a Touched event if you wanted something to happen between specific coordinates, Or you could find how many Studs the Player is from a certain "Part" If you want the Player's position you can do that via

local Pos = player.Character.Torso.Position

Switch "Torso" to "UpperTorso" or another R15 Body part if R15 Enabled,

and if you wanted to do a touched event you would put a Part down in size it to what you want then put

Part.Touched:connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    -- Script

end)

and if you wanted to find out the Studs between an Object and the Player you would have to do:

function GetInrange(part)
    return (part.Position - game.Players.LocalPlayer.Character.Torso.Position).magnitude >50 
end

If you wanted a different position each time I would eliminate the Touched event and use something such as Studs then add your Sound, If I was not of any help please Comment or Rep me down.

0
You really shouldn't be using Touched for this. All you need is a designated Position, and magnitude. ScriptGuider 5640 — 8y
Ad

Answer this question