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

How to make player respawn after health = 0?

Asked by 6 years ago

Hello! I am a new builder and one thing has been nagging at me for a while. When I use any weapon in my game to kill players, their health goes to 0, and it is visible on the health bar, however, they do not die and just continue as if they had not been damaged at all.

I have tried very hard, but had no success in scripting this. I want a script where when a players health = 0, they respawn back to the spawn point. I am sorry I do not have any code, since I am a new scripter and hopefull to learn.

Thankyou!

1 answer

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

(This answer only applies if you have FilteringEnabled on; you can check it by looking in the Properties window with the Workspace selected.)

The default behaviour is for the player to die when their health reaches 0. Assuming you haven't changed that (and haven't changed the health system and haven't changed the player's default model), then what you're describing is what one would expect if your weapons you're using were not designed for FilteringEnabled -- that is, they attempt to hurt the player's Health directly. This causes their health drain to be only visible to you. To fix this, you have to have the server run the health drain code instead of the client. A very insecure method is to have a RemoteEvent that lets any client tell the server who they hit and how much damage they caused. Do note that scripting it like this is the easiest route, with the drawback that any exploiter will be able to kill everyone else in the server instantly and repeatedly (though you can add checks to limit this, if you know how). An even more insecure method is to disable FilteringEnabled (granting exploiters free reign), but at least your game would be playable if you just invite a few trusted friends into it.

Edit: Here's the insecure method. In every weapon, find where it damages the player and instead fire a RemoteEvent that you have placed in game.ReplicatedStorage named "DamagePlayer"

--In every weapon, instead of
hum:TakeDamage(5)
--or instead of
hum.Health = hum.Health - 5
--do:
game.ReplicatedStorage.DamagePlayer:FireServer(hum, 5)

--In a Script in ServerScriptService or Workspace:
game.ReplicatedStorage.DamagePlayer.OnServerEvent:Connect(function(player, humanoid, damage)
    if not humanoid then return end -- Make sure the humanoid (still) exists
    if type(damage) ~= "number" or damage < 0 or damage > 100 then return end -- This makes sure that, if we continue on in the function, 'damage' is a reasonable value. If it isn't, you either have a bug or an exploiter. NOTE: If you can put the maximum damage to below 100 (ex if all your weapons do no more than 20 damage), then change the '> 100' to '> 20' (or whatever value you need) to reduce the amount of damage an exploiter can do.
    --TODO Check to make sure that 'player' can attack 'humanoid'. ex, have they made a lot of attacks recently (more than is possible for a player)? Is the 'player' anywhere near 'humanoid' (but be careful checking that if you have ranged weapons - ex, you expect a sniper gun to do damage from far away!)? The better you can make this check, the less likely an exploiter can instant-kill everyone.
    --Assuming all is well:
    humanoid:TakeDamage(damage)
end)

A superior method (requires more scripting skills) is the client telling the server the weapon used and the angle it was fired at; the server can then determine if any damage should be applied to anyone. Note that this is still weak to aim-bots, but at least exploiters wouldn't be able to kill people through walls.

0
Yes, I have filtering enabled. I am simply not able to understand any of the solutions you gave because of my inexperience. However, you said the weapons are not compatible to filtering enabled, thus makes it so the player cannot die? To fix this, could I just remove all weapons from the game? BADABOO2016 3 — 6y
0
If you remove all your weapons, you won't have any malfunctioning weapons, but then you won't have any way of attacking other players, right? Try reading http://wiki.roblox.com/index.php?title=Experimental_Mode and http://wiki.roblox.com/index.php?title=Converting_Experimental_Mode_Games . chess123mate 5873 — 6y
0
I have edited my answer with an example of one of the solutions I mentioned chess123mate 5873 — 6y
0
I have tried to do your solution on the "Raycast Assault Rifle" by TravellingElectron. I tried it on other guns as well. It does not work still. Could you please show me how it is done on the Raycast Assault Rifle? BADABOO2016 3 — 6y
View all comments (5 more)
0
It doesnt have to be the Raycast Assault Rifle, it can be any gun it doesn't matter. Thanks! BADABOO2016 3 — 6y
0
It works for me. I have done as you requested. I didn't test it Online, but I believe the "Start Server" test I performed (with 2 players) was sufficient. I've uploaded the model (you should be able to find it in my inventory). chess123mate 5873 — 6y
0
I got it, and found I was doing something wrong. Thanks for all your help bro BADABOO2016 3 — 6y
0
I got it, and found I was doing something wrong. Thanks for all your help bro BADABOO2016 3 — 6y
0
Glad you figured it out =) chess123mate 5873 — 6y
Ad

Answer this question