So i have a Distance Module, But when i use it on the player it doesnt work well. Im making a sword that detects if the player is near anyone.
local Module = require(game.ReplicatedStorage.DistanceModule)
script.Parent.Parent.Event.OnServerEvent:Connect(function(plr)
local Character = plr.Character
--local OtherHumanoid = v.Character
for i,v in pairs(game.Players:GetPlayers()) do
if v.Character.HumanoidRootPart ~= Character.HumanoidRootPart then
local HumanoidRoot = Character.HumanoidRootPart
Module.InDistance(plr, HumanoidRoot, v)
end
end
end)
The weapon Server
local DistanceModule = {}
local Distances = 10
function DistanceModule.InDistance(Player, Part, OtherPlayer)
local Distance = Player:DistanceFromCharacter(Part.Position)
if Distance <= Distances then
OtherPlayer.Character.Humanoid:TakeDamage(25)
print("Player is near")
elseif Distance >= Distances then
print("Player is not near")
end
end
return DistanceModule
It works but the player could be 100 studs and still do damage