I am making a game where you have health and this is the script that i used for the health pack and i dont know why it doesnt work even when i damage myself
local canPickup = true
script.Parent.Model.Touched:Connect(function(hit)
if hit.Parent ~= nil and game.Players:GetPlayerFromCharacter(hit.Parent) and canPickup == true then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local playerHealth = player.Character.Humanoid.Health
local playerMaxHealth = player.Character.Humanoid.MaxHealth
if playerHealth ~= playerMaxHealth and playerHealth > 0 then
canPickup = false
if playerHealth + (playerHealth / 2) > playerMaxHealth then
playerHealth = playerHealth + (playerMaxHealth - playerHealth)
else
playerHealth = playerHealth + (playerMaxHealth / 2)
end
script.Parent.Model.Transparency = 1
wait(10)
canPickup = true
script.Parent.Model.Transparency = 0
end
end
end)

3 comments
Non-literal value assignment is what you're doing. This means that the value of the variable changes but the actual value does not change. Assign a variable to the Humanoid then change Health and MaxHealth from that variable, but do not assign the health values to variables.
Still doesn't work
Okay, then check for hit:FindFirstAncestorOfClass("Model") and also check for a player from that model instead of trying to index the parent