CD = script.Parent.ClickDetector
local player = game.Players.LocalPlayer
CD.MouseClick:Connect(function(click)
if click.Humanoid.Health < 100 then
click.Humanoid.Health = click.Humanoid.Health + 30
end
end)
Ok now that all the issues in your script are show this is how to fix it:
script.Parent.MouseClick:Connect(function(player)
local human=player.Character:FindFirstChild("Humanoid")
if human ~=nil and human.Health<human.MaxHealth then
human.Health=human.Health+30
print(human.Parent.Name)
end
end)
Also if you new to scripting you should go for simple stuff first, as going directly for complicated topics only helps to frustrate and discourage you.For Example when I just started I did simple things like building volcanoes, scripting traffic lights, playing sounds, making doors with click detectors, and similiar things before aiming to make actual games.
Also use error messages to fix your script, you can copy and paste error messages into google which will help you understand what they mean.Finally make sure to read over your script for incorrect indexing, indexing is trying to reference an object for example "
game.Workspace.Object
", so don't incorrectly spell it like "game.Workspace.object" make sure the capitlization and spelling are exact. Also if you want to reference something that has a space in it's name without an error then do this "game.Workspace["Ob ject"] " a string inside square brackets without a ' . ' before it
1 comment
The reason is because the click parameter is a player, not the character. Get the character by click.Character. Then you can get Humanoid because it's a child of the character.