✓ Accepted answer
Explanation
If you don't want to use a loop to determine the magnitude, you can use a :GetPropertyChangedSignal() event to determine changes in the player's character model (note that some of these, like position will not be accounted for once they have loaded into the workspace)
To get the player's character, we will be using the CharacterAdded event of the player's instance, which is taken from when the player joins the game.
One of these properties, the Humanoid's MoveDirection (which changes when the player moves outside of a straight line) can be used as an optional connection to determine the difference in magnitude.
Revised Server Script (Move Direction)
game:GetService("Players").PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
local human = Character:WaitForChild("Humanoid")
local root = Character:WaitForChild("HumanoidRootPart")
human:GetPropertyChangedSignal("MoveDirection"):Connect(function()
if (Vector3.new(-5.15, 6.05, 8.4) - root.Position).magnitude <= 6 then
local elev = Player:WaitForChild("Settings"):WaitForChild("currently_inside_lobby_elevator")
local remote = game:GetService("ReplicatedStorage"):WaitForChild("RE"):WaitForChild("LobbyElevator")
if elev.Value ~= true then
elev.Value = true
remote:FireClient(Player, true)
end
end
end)
end)
end)
However, since a player might move in a straight line to reach the preferred magnitude, we can use .Touched events to check the magnitude since as a player moves, they must touch a surface at some point.
Revised Server Script (.Touched Event)
game:GetService("Players").PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
Character.AncestryChanged:Connect(function(child, parent)
if parent == workspace then
for i, v in pairs(Character:GetDescendants()) do
if v:IsA("BasePart") then
v.Touched:Connect(function()
local root = Character:WaitForChild("HumanoidRootPart")
if (Vector3.new(-5.15, 6.05, 8.4) - root.Position).magnitude <= 6 then
local elev = Player:WaitForChild("Settings"):WaitForChild("currently_inside_lobby_elevator")
local remote = game:GetService("ReplicatedStorage"):WaitForChild("RE"):WaitForChild("LobbyElevator")
if elev.Value ~= true then
elev.Value = true
remote:FireClient(Player,true)
end
end
end)
end
end
end
end)
end)
end)
2 comments
Run the loop from the client
you can use Humanoid's Running event