This is kinda hard to explain, but i’ll do my best.
So what i’m trying to do is, when you go near a downed player, a revive gui is supposed to pop up on your screen, and it does work as intended when there is only 2 players in the server.
But when there is more than 2 players, it doesn’t work as intended
Whenever i try to go near a downed player, sometimes it doesnt even show the gui, and it spams “PlayerName is close” in the console, and whenever i tried to revive him, i revive someone else instead
I would like some help, or just a better way to do this, thanks. - thunderdos31
Here is the LocalScript in StarterCharacterScripts (but it is shortened, lmk if you need more info):
local player = game.Players.LocalPlayer
local character = player.Character
local myHuman = character:WaitForChild("Humanoid")
local hrp = character:WaitForChild("HumanoidRootPart")
local INTERVAL = 0.5
local nextStep = tick() + INTERVAL
local revivePrompt = player.PlayerGui.Prompts:WaitForChild("RevivePrompt") -- RevivePrompt is a frame
local canRevive = false
game:GetService("RunService").Heartbeat:Connect(function(dt)
if (tick() >= nextStep) then
for i, otherPlayer in pairs (game.Players:GetPlayers()) do
if not otherPlayer then return end
if otherPlayer ~= player then
local otherChar = otherPlayer.Character
if not otherChar then return end
local otherHumanoid = otherChar:FindFirstChild("Humanoid")
if not otherHumanoid then return end
local otherRoot = otherChar:FindFirstChild("HumanoidRootPart")
if not otherRoot then return end
local downed = otherChar:FindFirstChild("Downed") -- Downed is a BoolValue inside thecharacter
if downed then
if downed.Value == true then
local distance = player:DistanceFromCharacter(otherRoot.Position)
if distance < 9 then -- if the downed player is near you, show the gui
local reviving = otherChar:FindFirstChild("Reviving")
local Pinned = otherChar:FindFirstChild("Pinned")
local Stunned = otherChar:FindFirstChild("IsStunned")
local RagdollTrigger = otherChar:FindFirstChild("RagdollTrigger")
canRevive = true
revivePrompt.Visible = true
revivePrompt.PlayerName.Text = "Revive "..otherPlayer.Name
print(otherPlayer.Name .. " is close")
else -- if the player is too far, then hide the gui
canRevive = false
revivePrompt.Visible = false
end
end
end
end
end
end
end)