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

What is wrong with this script?

Asked by 10 years ago
local button = script.Parent.Button
local player = game.Workspace:FindFirstChild("Player")

function onTouch(button)
    if player.Humanoid.Health < 100 then
        player.Humanoid.Health = 100
    end
end

button.Touched:connect(onTouch)

This script is supposed to be an button that when touched it will heal the player if their health is less than 100.I have tested the script but it says: 16:50:20.869 - Workspace.HealButton.Script1:5: attempt to index upvalue 'player' (a nil value) 16:50:20.870 - Stack Begin 16:50:20.871 - Script 'Workspace.HealButton.Script1', Line 5 16:50:20.872 - Stack End 16:50:20.873 - Disconnected event because of exception

If anyone can see what I have done wrong and furthermore fix my errors I would be really greatful.

Answer this question