1. What do I want to achieve?
I made a combat system using Magnitude, the player must press F to fire the pvp remote event, detect players nearby and damage them.
2. What is the issue?
The script:
pvp.Damage.OnServerEvent:Connect(function(player: Player)
if table.find(damage_cooldown, player) or player.BatMode.Value then return end
table.insert(damage_cooldown, player)
task.delay(claw_cooldown, function()
local foundPlr = table.find(damage_cooldown, player)
if foundPlr then
table.remove(damage_cooldown, foundPlr)
end
end)
local char = player.Character
local humanoid = char:FindFirstChild("Humanoid")
if not humanoid then return end
if humanoid.Health <= 0 then return end
playSfx:FireAllClients(player.Character, "Slash")
for _, vampire in players:GetPlayers() do
print(vampire.Name .. " is in players list.")
local vampChar = vampire.Character
local distance = (char.PrimaryPart.Position - vampChar.HumanoidRootPart.Position).Magnitude
if distance < 8 then
if vampChar.Humanoid.Health <= 0 or vampire == plr then return end
print(vampire.Name .. " is alive.")
PlrDamage(plr, vampire)
end
end
end)
The line issue:
for _, vampire in players:GetPlayers() do
print(vampire.Name .. " is in players list.")
local vampChar = vampire.Character
local distance = (char.PrimaryPart.Position - vampChar.HumanoidRootPart.Position).Magnitude
if distance < 8 then
if vampChar.Humanoid.Health <= 0 or vampire == plr then return end
print(vampire.Name .. " is alive.")
PlrDamage(plr, vampire)
end
end
For some reason, when a player joined the server, that player can damage the ones that have been in the server before the new one, however, the other players aren’t able to damage the new player.
3. What solutions have I tried so far?
- I added prints to know which line starts breaking the detection, the
print(vampire.Name .. " is in players list.")shows in the output, but all lines belowlocal vampChar = vampire.Characterdo not anymore. - I even tried to add a pairs or ipairs in the
for _, vampire in players:GetPlayers() dobut it’s still the same.
No errors in the output, just the name of the player in the players list. What am I doing wrong here?