Hi devs. I’m trying to make a fair combat system, and I would like to make it so if a player is within a certain range of another player, then they cannot reset their character.
Here is the normal script for canceling a players reset button. But I don’t know how to modify this script to detect if another player is in a certain range, as I’m quite new to scripting.
Quickly made on mobile, expect bugs and/ or errors.
local players = game:GetService("Players")
local minDistance = 50
local function checkDistance(character)
--
if character == nil then return end
if character.PrimaryPart == nil then return end
--
local humanoid = character:FindFirstChildOfClass("Humanoid")
if not humanoid then continue end
if humanoid.Health <= 0 then continuen end
--
for _, checkingPlayer in players:GetPlayers() do
--
local checkingCharacter = checkingPlayer.Character
if not checkingCharacter then continue end
--
local checkingHumanoid = checkingCharacter:FindFirstChildOfClass("Humanoid")
if not checkingHumanoid then continue end
if checkingHumanoid.Health <= 0 then continue end
--
local distance = (character.PrimaryPart.Position - checkingCharacter.PrimaryPart.Position).Magnitude
--
if distance <= minDistance then
game:GetService("StarterGui"):SetCore("ResetButtonCallback", false)
break
end
--
end
end
end)
Example:
local runService = game:GetService("RunService")
local player = game:GetService("Players").LocalPlayer
runService.RenderStepped:Connect(function()
local character = player.Character
checkDistance(character)
end)