Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I'm Trying To Create A Vampire Script Where You Regain Health After Killing a Player. What's wrong?

It's for regaining all of your health when you kill a player, I need to know why it's not working.


Players = game:GetService("Players") -- In case someone renames Players or something
Players.PlayerAdded:connect(function(Player) -- When someone joins
    --// You can add other stuff here, too.
    Player.CharacterAdded:connect(function(Character) -- When they respawn (Get a new Character)
        local Humanoid = Character:WaitForChild("Humanoid") -- Find Humanoid
        Humanoid.Died:connect(function() -- Detects for when the Humanoid dies
            if Humanoid:FindFirstChild("creator") ~= nil then -- Checks for a Killed
                local Killer = Humanoid.creator.Value -- Gets Killer
                local player = game.Players.LocalPlayer -- Gets the player
					local char = player.Character --Gets the player's character
						char.Humanoid.MaxHealth = 100 --Sets the MaxHealth of the Humanoid to 100
						char.Humanoid.Health = 100 --Sets the health to 100, so that the player is at full HP)
            end -- Ends the if
            -- For the Dead guy, you can do stuff to him here.
        end)
    end)
end) -- Another End w/ a Bracket

4 comments

0

Ok hold on I'm confused, is the Killer suppose to be the vampire? If that is the case, then this is not working because you are setting the health for the dead player

0

Also, a serverscript cannot define the local player

0

Then what should I do?

0

Creator is not rly a good think to use when dealing with deaths.

1 answer

You cannot access localplayer from a serverscript, and if you could your script would be changing the person killed's value, fix:

Players = game:GetService("Players") 
Players.PlayerAdded:connect(function(Player)
   
    Player.CharacterAdded:connect(function(Character) 
        local Humanoid = Character:WaitForChild("Humanoid") 
        Humanoid.Died:connect(function() 
            if Humanoid:FindFirstChild("creator") ~= nil then 
                local Killer = Humanoid.creator.Value 
                local killerchar = game.Workspace:FindFirstChild(Killer)
local killerhum = killerchar:FindFirstChild("Humanoid")

if killerhum then
killerhum.Health = 100
end
                       
            end 
            
        end)
    end)
end) 

This discussion is preserved as it was. New answers, comments, and votes are closed.