As far as the title goes I have made this incapacitation script where I wanna add a revive feature but for some reason it doesnt add a new instance of a proximity prompt. Any ideas?
btw my code might be very messy
local onPlayerLoaded = function(player)
local onCharacterLoaded = function(Char)
local humanoid = Char:WaitForChild("Humanoid")
local hrp = Char:WaitForChild("HumanoidRootPart")
wait(2)
local anim = humanoid:LoadAnimation(incap)
local anim2 = humanoid:LoadAnimation(recovered)
--part 1
humanoid.HealthChanged:Connect(function()
if humanoid.Health <= 50 then
print("player incapacitated")
local uhsclone = incapuhs:Clone()
uhsclone.Parent = player.PlayerGui
anim:Play()
hrp.Anchored = true
task.wait(5)
hrp.Anchored = false
wait(2.5)
uhsclone:Destroy()
while humanoid.Health <= 69 do
wait(2)
humanoid:UnequipTools()
end
elseif humanoid.Health >= 70 then
print("player is recovering")
hrp.Anchored = false
humanoid.WalkSpeed = 5
if humanoid.Health == 100 then
print("player fully recovered or healthy")
humanoid.WalkSpeed = 16
anim:Stop()
end
if humanoid.Health <= 70 then
wait(1)
local proxPrompt = Instance.new("ProximityPrompt")
player.CharacterAdded:Wait()
proxPrompt.Parent = player.Character:WaitForChild("Torso")
proxPrompt.RequiresLineOfSight = false
proxPrompt.Triggered:Connect(function()
-- do stuff here
end)
end
end;
end);
end;
player.CharacterAdded:Connect(onCharacterLoaded);
if(player.Character) then onCharacterLoaded(player.Character) end;
end;
game.Players.PlayerAdded:Connect(onPlayerLoaded);
for _, p in pairs(game:GetService("Players"):GetPlayers()) do
onPlayerLoaded(p);
end;
if humanoid.Health <= 70 then
wait(1)
local proxPrompt = Instance.new("ProximityPrompt")
player.CharacterAdded:Wait()
proxPrompt.Parent = player.Character:WaitForChild("Torso")
proxPrompt.RequiresLineOfSight = false
proxPrompt.Triggered:Connect(function()
-- do stuff here
end)
It’s because you put the bottom snippit inside of the if humanoid.Health >= 70
while it only runs when humanoid.Health <= 70
because of that, it’ll only create the proximityprompt when your health is exactly 70.
You want the proximity prompt to only appear when your incapacitated right?
If so, you’ll want to move it over into the other half of the if statement, where you do incapacitate the character.
I’ve attempted this but it didn’t work?
Can you show what I’ve done wrong here?
humanoid.HealthChanged:Connect(function()
if humanoid.Health <= 50 then
print("player incapacitated")
local uhsclone = incapuhs:Clone()
uhsclone.Parent = player.PlayerGui
anim:Play()
hrp.Anchored = true
task.wait(5)
hrp.Anchored = false
wait(2.5)
uhsclone:Destroy()
local proxPrompt = Instance.new("ProximityPrompt")
player.CharacterAdded:Wait()
proxPrompt.Parent = player.Character:WaitForChild("Torso")
proxPrompt.RequiresLineOfSight = false
proxPrompt.Triggered:Connect(function()
-- do stuff here
end)
while humanoid.Health <= 69 do
wait(2)
humanoid:UnequipTools()
end
elseif humanoid.Health >= 70 then
print("player is recovering")
hrp.Anchored = false
humanoid.WalkSpeed = 5
if humanoid.Health == 100 then
print("player fully recovered or healthy")
humanoid.WalkSpeed = 16
anim:Stop()
end
end;
end);
end;
player.CharacterAdded:Connect(onCharacterLoaded);
if(player.Character) then onCharacterLoaded(player.Character) end;
end;
game.Players.PlayerAdded:Connect(onPlayerLoaded);
for _, p in pairs(game:GetService("Players"):GetPlayers()) do
onPlayerLoaded(p);
end;
What’s breaking exactly? Is it still not making a proximity prompt when it prints “player incapacitated”?
Also I should note that, it looks like every time the humanoids health changes while below 50hp it’ll play the whole incapacitation sequence again.
Try doing
print(proxPrompt.Parent) after you’ve created it (also, check to see if the instance is actually under the characters torso in the explorer while the game is running)
Additionally, you can fix it running multiple times by doing something like a debounce. Where you set the debounce to true when you incapacitate the character, and set it to false when they wake back up. And just check to see if the debounce is already true when you go to incapacitate.
This is a sign that it never reaches that part of the script, and something is causing it to stall indefinitely.
Place prints throughout that whole section and find out where the prints stop.
humanoid.HealthChanged:Connect(function()
if humanoid.Health <= 50 then
print("player incapacitated")
local uhsclone = incapuhs:Clone()
uhsclone.Parent = player.PlayerGui
anim:Play()
hrp.Anchored = true
task.wait(5)
hrp.Anchored = false
wait(2.5)
uhsclone:Destroy()
print("test worked 1")
local proxPrompt = Instance.new("ProximityPrompt")
print("test worked 2 made proximity")
player.CharacterAdded:Wait()
proxPrompt.Parent = player.Character:WaitForChild("Torso")
print(proxPrompt.Parent)
proxPrompt.RequiresLineOfSight = false
proxPrompt.Triggered:Connect(function()
-- do stuff here
end)
print("test worked 3 worked")
while humanoid.Health <= 69 do
wait(2)
humanoid:UnequipTools()
end
After placing these down it seems the 3rd print doesn’t work…
Sorry I didn’t check my devforum tab for a long while, if you see this then you can attach a function to the humanoid.Died event to destroy the proximity prompt, additionally you can destroy the prompt when you successfully revive someone. And finally when the character recovers from being knocked out, you can do a :GetFirstChild() on the torso to see if they have a proximity prompt still and delete it.