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

Health pack for game does not work on touch?

Asked by 4 years ago

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)
1
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. DeceptiveCaster 3761 — 4y
0
Still doesn't work AradIsHere 2 — 4y
0
Okay, then check for hit:FindFirstAncestorOfClass("Model") and also check for a player from that model instead of trying to index the parent DeceptiveCaster 3761 — 4y

Answer this question