This isn’t a good solution, that forces you to be picky about damage.
Alright. So for example:
Humanoid.Health.Changed:Connect(function()
if Humanoid.Health <= 0 then
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Died, false)
end
It’s a easy fix
local WeaponDamage = 12
if Health > 10 and Health < WeaponDamage then
Health = 9
-- Damage the player
end
But this is just for learning, I agree that this is not a good way to do it
As long as the Humanoid never dies, things like FloorMaterial can be seen and calculated, which helps developers with (for example) things like ground impacts.
So your method works too as you said, it’s all about not making the Humanoid die in the end.
The thing is, I do this for a comission. So I don’t have acess to all the other spells wh someone else made. So I can’t use your method.
Oh I see, you can’t see the damaging script? That makes the comparison impossible.
Make the state disable on spawn then.
At first I meant to make the damage and current health compare, and if it was 0 or lower, it would disable the state before taking damage.
So like for example:
CharacterAdded → Humanoid:SetStateEnabled(Enum.HumanoidStateType.Died, false)
Yeah, make sure to define the Humanoid as a local variable and use WaitForChild() to avoid errors.
Alrighty. I will try it out. Thank you.
Now I’m infinite long dead and I don’t respawn. I think I will try to reload the character and TP the char to his old position.
You need to manually script the respawning process.
I recommend player:LoadCharacter()
Id recommend moving the Chatted event out of the CharacterAdded event as this may cause a large memory leak. Every time the character dies, it will add an additional event. These events will gather up, and lets say the character had died 100 times, the next time the character chats, it will set char.Humanoid.Health = 50
100 times instead of once. This can be very dangerous and will cause large amounts of lag every time you run that command.
That is not a possible thing to do. Once a Humanoid has 0 health, it will automatically have its state as “Dead”, which can not be changed. Once the player respawns, the old character is destroyed & Roblox requests a new one, that’s how you respawn.
What I suggest doing: Making a player’s Humanoid have, for example, 120 max health. Whenever the health is only 20 or below, down the player, the they can get revived if someone types “!revive”
Here’s an example script:
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local humanoid = char:WaitForChild("Humanoid")
humanoid:SetAttribute("Downed",false)
humanoid.HealthChanged:Connect(function()
if humanoid.Health <= 20 then
humanoid:SetAttribute("Downed",true)
--you can put other downed limitations here
else
if humanoid:GetAttribute("Downed") then
humanoid:SetAttribute("Downed",false)
end
end
end)
end)
player.Chatted:Connect(function(text)
if text == "!revive" then
if player.Character and player.Character.Humanoid:GetAttribute("Downed") then
player.Character.Humanoid.Health = 50
end
end
end)
end)
Also please don’t put player.Chatted
when to CharacterAdded events, otherwise that might cause some memory issues. The event does not get disconnected whenever the signal is fired again.
Incorrect, read above.
Disabling state Died prevents the whole thing from happening.
Disabling died or BreakJointsOnDeath also prevents automatic respawn.
Hmm, would not agree, first of all a character dying a 100 times is not much, secondly setting the health to 50 isn’t very intensive. Another answer is that you can simply disconnect the event once the player dies.
You would have to save whatever you want to save in a seperate folder or clone it, and teleport the player back on respawn, it is currrently impossible to revivie a player
THOUGH ive never tested you might be able to change the state of player from died
Something like that ^
local deathPositions = {} -- Place where we save our positions
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
deathPositions[player] = Vector3.new()
player.CharacterAdded:Connect(function(char)
char.Humanoid.Died:Connect(function()
deathPositions[player] = char.HumanoidRootPart.Position + Vector3.new(0, 1, 0)
end)
end)
player.Chatted:Connect(function(msg)
local split = string.split(msg, " ")
local command, destPlayer = split[1], split[2] and Players:FindFirstChild(split[2]) or player
if command == "!revive" then
if destPlayer then
destPlayer:LoadCharacter()
destPlayer.Character:SetPrimaryPartCFrame(CFrame.new(deathPositions[destPlayer]))
else
player:LoadCharacter()
player.Character:SetPrimaryPartCFrame(CFrame.new(deathPositions[destPlayer]))
end
end
end)
end)
Quick question where would this script go? And is it a script or local script.
You must create a script and put it at ServerScriptService