Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I prevent everyone from being revived?

Asked by 3 years ago

I don't know how to prevent everyone from being revived. I just only wanted that person who is getting affected to be affected.

https://www.youtube.com/watch?v=z8dopZLAB04 - Video on the problem

local ProximityPromptService = game:GetService("ProximityPromptService")
local DownedHumanoidRootPart = script.Parent.Parent
local Character = DownedHumanoidRootPart.Parent
local Revived = Character.Humanoid:LoadAnimation(script.Revived)
local Debries = game:GetService("Debris")
local ServerStorage = game.ServerStorage
local Reviving
local SoundClone
local GotRevived

local function onPromptHoldBegan(_, player)
    Reviving = player.Character:WaitForChild("Humanoid"):LoadAnimation(script.RevivingPlayer)
    if player.Character.Status.IsDowned.Value == false then
        player.Character:WaitForChild("Humanoid").WalkSpeed -= 16
        player.Character:WaitForChild("Humanoid").JumpPower -= 50
        player.Character:WaitForChild("Status"):WaitForChild("IsReviving").Value = true
        Reviving:Play()
        SoundClone = ServerStorage:WaitForChild("Downed"):WaitForChild("VoiceLines"):WaitForChild("RevivingPlayer"):WaitForChild("Reviving"..math.random(1,8)):Clone()
        SoundClone.Parent = DownedHumanoidRootPart
        SoundClone:Play()
        -- Model weld code (doing this to save space)
        Stim:WaitForChild("Grip"):WaitForChild("ReviveSound"):Play()
        Character.Status.BeingRevived.Value = true
        DownedHumanoidRootPart:WaitForChild("ReviveIcon"):WaitForChild("ImageLabel").ImageColor3 = Color3.new(255, 255, 255)
    end
end

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Easy fix, just check if the player has the right name.

local ProximityPromptService = game:GetService("ProximityPromptService")
local DownedHumanoidRootPart = script.Parent.Parent
local Character = DownedHumanoidRootPart.Parent
local Revived = Character.Humanoid:LoadAnimation(script.Revived)
local Debries = game:GetService("Debris")
local ServerStorage = game.ServerStorage
local Reviving
local SoundClone
local GotRevived

local function onPromptHoldBegan(_, player)
    if Character.Name = "" then -- insert name of the specific player you only want to be revived
        Reviving = player.Character:WaitForChild("Humanoid"):LoadAnimation(script.RevivingPlayer)
    if player.Character.Status.IsDowned.Value == false then
            player.Character:WaitForChild("Humanoid").WalkSpeed -= 16
            player.Character:WaitForChild("Humanoid").JumpPower -= 50
            player.Character:WaitForChild("Status"):WaitForChild("IsReviving").Value = true
            Reviving:Play()
            SoundClone = ServerStorage:WaitForChild("Downed"):WaitForChild("VoiceLines"):WaitForChild("RevivingPlayer"):WaitForChild("Reviving"..math.random(1,8)):Clone()
            SoundClone.Parent = DownedHumanoidRootPart
            SoundClone:Play()
            -- Model weld code (doing this to save space)
            Stim:WaitForChild("Grip"):WaitForChild("ReviveSound"):Play()
            Character.Status.BeingRevived.Value = true
    DownedHumanoidRootPart:WaitForChild("ReviveIcon"):WaitForChild("ImageLabel").ImageColor3 = Color3.new(255, 255, 255)
    end
    end
end
0
Thing is that I want others to be revived, not specific players. The video I showed shows that everyone being revived even tho I only targeted one player TheBuliderMC 84 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

You haven't shown us your entire script (nothing in your script actually revives any player) but some notes:

  • Reviving should either be local or per-player (otherwise if 2 people try to revive the same person you'll be trying to remember two animations in one variable - one of them will be overwritten). If the animation ends on its own then you can just make it local.
  • SoundClone is the same way. If you need to access it again, you have two options:
    • After cloning it, name it something specific (like "ReviveSound") so that you can find it again using :FindFirstChild("ReviveSound")
    • Save it per player (you'll need to use tables - be sure to also set table values for any player who stops using the prompt or else you'll have a memory leak)
  • You currently set Character.Status.BeingRevived.Value = true in onPromptHoldBegan. Do you set it to false in onPromptHoldEnd if it didn't complete?
  • Do you have some other script that is looking through all players to see who has BeingRevived.Value == true? If so, this is a problem, because this means that your script is willing to:
    • Revive multiple players when it should only revive a specific player
    • Revive players who have started being revived (but not yet finished)

Less important notes about SoundClone = ServerStorage:WaitForChild("Downed"):WaitForChild("VoiceLines"):WaitForChild("RevivingPlayer"):WaitForChild("Reviving"..math.random(1,8)):Clone():

  • You don't need WaitForChild when accessing things that are in the game from the beginning (this does not include anything that is cloned by a script or by Roblox, such as guis that are cloned from StarterGui, but does include probably everything in ServerStorage, unless you clone stuff in there after the game starts)
  • If RevivingPlayer is a folder currently containing only Reviving sounds, it'd be more resistant to changes if you picked a random child:
local RevivingSounds = ServerStorage.Downed.VoiceLines.RevivingPlayer:GetChildren() -- this can go near the top

SoundClone = RevivingSounds[math.random(1, #RevivingSounds)] -- this replaces the current SoundClone = line

Answer this question