Changing player health using script

local pvp = false
if pvp == false then
	
end

in that loop, I want it so if pvp is false the players health = infinity and they cant be hurt by players with pvp on. How?

1 Like

You would set the health by using math.huge Like this:

local Pvp = false
local humanoid = path.to.players.humanoid
while true do
If not Pvp then
humanoid.health = math.huge
end
end

Oh yes I forgot about that, yes that’s the best way to do it.

That script underlines anyway…

You will have to use infinite loop as well to check if pvp value is false or true. I’d do it like this:

local pvp = game.Players.LocalPlayer:FindFirstChild("pvp").Value --path to your pvp value
local player = game.Players.LocalPlayer

while true do
  if not pvp then
     workspace[player.Name]:FindFirstChild("Humanoid").Health = 100
  end
  wait(0.1)
end

@CodedE44OR your script is going to crash because you are using loop too fast, I’d recommend adding wait inside of while true do loop.

2 Likes

why cant i set local pvp to true/false

Are you changing it in the script and the change is not visible?

Well to change this, you can click a gui to toggle pvp on/off

I’d use remote events to change the value of this pvp value since there can be many disturbances included while changing this value.

local script (GUI button)

script.Parent.MouseButton1Down:Connect(function()
      -- Fire Event
end)

server

Event.OnServerEvent:Connect(function()
    -- change value of the pvp
end)

Im getting confused
30 characters

You will have scripts to change the value and one for checking the value (I sent two posts above).

Would this work? would the players health be 0 for instance

local pvp = false
local plr = game.Players:FindFirstChild("Humanoid")
if pvp == false then
	plr.Health = 0
	
	
end
1 Like

No but this would:

local pvp = false
local plr = game.Players.LocalPlayer
workspace:WaitForChild(plr.Name)

if pvp == false then
	workspace[plr.Name]:FindFirstChild("Humanoid").Health = 0
end

But I wanna refer to all players that have pvp off not just a single player with that name…

Aand your gone D: …

Would this work?

local pvp = false
local plr = game.Players.LocalPlayer
workspace:WaitForChild(plr.Name)

if pvp == false then
	workspace:FindFirstChild("Humanoid").Health = 0
end

Thanks for ignoring me…

Sorry I had lunch. This is not going to work because you are looking for Humanoid inside workspace first instead of looking for player first and then inside player for Humanoid.

I dont think he was ignoring you? I’m pretty sure he has to go to other places like everybody else does.

1 Like

well I wanna refer to all the players with pvp on not just a certain one.