when i press E on my keyboard, it should loop through other players to see if the player exists and if it finds a player within distance of the player that pressed E, it will tell the distance between the two players.
error:
local script:
local pickupPlayerEvent = game.ReplicatedStorage:WaitForChild("pickupPlayerEvent")
local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(input, gameproc)
if input.KeyCode == Enum.KeyCode.E then
print("pressed e")
local myHRP:MeshPart = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
pickupPlayerEvent:FireServer(myHRP)
print("Firing...")
end
end)
script:
local pickupPlayerEvent = game.ReplicatedStorage:WaitForChild("pickupPlayerEvent")
pickupPlayerEvent.OnServerEvent:Connect(function(myplr, myHRP:MeshPart)
for _, otherPlr in ipairs(game.Players:GetPlayers()) do
local otherCharacter = otherPlr.Character
if not otherCharacter then continue end
local otherHRP:MeshPart = otherCharacter:WaitForChild("HumanoidRootPart")
if not otherHRP then continue end
local dist = (otherHRP - myHRP).Magnitude
if dist < 10 then
print(string.format("%s is close (%.1f studs away)", otherPlr.Name, dist))
end
end
end)