local player = game.Players.LocalPlayer game.Workspace:WaitForChild(player.Name).Humanoid.Died:connect(function() repeat wait() until game.Workspace[player.Name].Humanoid ~= nil if game.Workspace[player.Name].Humanoid ~= nil then if game:GetService("MarketplaceService"):PlayerOwnsAsset(player, 442799450) or player.Name == "uwot_m9" or player.Name == "Player1" or player.Name == "Ractrium" or player.Name == "Ravogan" then --Double health game.Workspace:WaitForChild(player.Name).Humanoid.MaxHealth = 200 game.Workspace:WaitForChild(player.Name).Humanoid.Health = 200 else end if game.Workspace:WaitForChild(player.Name):WaitForChild("Health") then game.Workspace:WaitForChild(player.Name).Health:Remove() script.Health.Parent = game.Workspace[player.Name] wait() game.Workspace[player.Name]:WaitForChild("Health").Disabled = false end end end)
There's my script, what is happening is it checks if the player is died, and repeats wait() until humanoid isn't nil, and checks if they own the gamepass and gives them double health, and inserts a modified health script, also.
But...none of it works, how do you check when the player is living again after he/she dies? Thanks for all help!
You can use the CharacterAdded
event to check when he respawns but this also checks for when his character is loaded into the game.
In general it is not good to change things like HP on the client side as this is secure information.
Events such as the humanoid died should also be done on the server. For players the CharacterAdded is used to setup properties for the player each time the character is added to the workspace so we don't need to check for when the player dies.
As currently this is done in a local script I have changed this into a server script:-
local mps = game:GetService("MarketplaceService") -- so we dont waste time getting the service each time -- a list of player who can get the HP with no gamepass -- this works as true is returned when found or nil when the player is not found nil in logic returns false local plrList = { ["uwot_m9"] = true, ["Player1"] = true, ["Ractrium"] = true, ["Ravogan"] = true } game.Players.PlayerAdded:connect(function(plr) -- add the ebent to the player when they join plr.CharacterAdded:connect(function(plrModel) -- this will run each time the spawn local plrNew = game.Players:GetPlayerFromCharacter(plrModel) -- it might be better to sore a value it the pass is present so we dont need to check each time if mps:PlayerOwnsAsset(plrNew, 442799450) or plrList[plrNew.Name] then -- give player more HP givePlrHP(plrModel) end -- I do not know what the purpose of this part so i cannot change this -- if game.Workspace:WaitForChild(player.Name):WaitForChild("Health") then -- game.Workspace:WaitForChild(player.Name).Health:Remove() -- script.Health.Parent = game.Workspace[player.Name] -- wait() -- game.Workspace[player.Name]:WaitForChild("Health").Disabled = false -- end end) end) -- small function to give the hp function givePlrHP(plrModel) local hum = plrModel:WaitForChild("Humanoid") hum.MaxHealth = 200 hum.Health = 200 end
Only one small change is that I have added a table. This will help when adding more people to check as you currently check for each name.
As this has be turned into a server script please comment if you need any more help in understanding how/why this works.
Hope this helps.