The “if statement” inside the proximity prompt function is not running the way I want.
local Part = script.Parent
local Prompt = Part.ProximityPrompt
--
Prompt.Triggered:Connect(function(player)
--
local Character = player.Character or player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
--
if Humanoid.Health < Humanoid.MaxHealth then
--
Humanoid.Health = Humanoid.Health + 4
--
else
print("Already at MaxHealth")
end
--
end)
The problem is that when the Humanoid has less than MaxHealth it still prints “Already at MaxHealth”
Try to put elseif Humanoid.Health > Humanoid.MaxHealth then. This is testing to see if the Humanoid has less more health than max health, by using the greater than symbol. Let me know if it works or doesn’t.
Maybe try to remove the or player.CharacterAdded:Wait() function. Just keep the player.Character. See if that works. You might be getting stuck on the wait function for CharacterAdded
Nope… still doesn’t seem to run. I mean it runs without errors, but even when the player is damaged and not at Max Health it still prints “Already at MaxHealth”
Prompt.Triggered:Connect(function(player)
--
local Character = player.Character or player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChild("Humanoid")
--
if Humanoid.Health < Humanoid.MaxHealth then
--
print("Before Adding 4")
Humanoid.Health = Humanoid.Health + 4
print("After Adding 4")
--
else
print("Already at MaxHealth")
end
--
end)
Are you decreasing the humanoid’s health on the client? Because after decreasing the humanoid’s health on the server, the prompt seemed to work for me.
local Part = script.Parent
local Prompt = Part.ProximityPrompt
--
Prompt.Triggered:Connect(function(player)
--
local Character = player.Character or player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChild("Humanoid")
--
Humanoid.Health = Humanoid.Health + 4
--
end)
the reason this happens is (probably) because you are decreasing your health from the client. try switching to the ‘server’ view in the studio and decreasing your health.
if it’s not the reason, then sorry, but I don’t have any ideas left anymore.