What I mean is, in the problematic area indicated below, where I should be able to make the script half as long I couldn't. I tried inpairs, strings, variables, and some other unmemorable attempts.. I just know too little about what I am doing to fix the problem.
wait() player = game.Players.LocalPlayer hum = player.Character.Humanoid local n = {"Player1", "pmcdonough"} hum.HealthChanged:connect(function() if hum.Parent.Name == "Player1" then--HERE lies the issues I am having. "Name == Player1 **or** pmcdonough" is the effect I would like. if hum.Health < 100 then repeat hum.Health = hum.Health + .01 wait() until hum.Health == 100 -- Doubling bit. Reason I need help compressing. elseif hum.Parent.Name == "pmcdonough" then if hum.Health < 100 then repeat hum.Health = hum.Health + .01 wait() until hum.Health == 100 end end end end)
As M39a9am3R pointed out, you can simply do:
if hum.Parent.Name == "this" or hum.Parent.Name == "that" then -- code end
However, this is not a very clean solution. It would be ideal to have a table with all the names, and to check if they should, in this case, heal then it should be as simple as checking if it is in the table.
A common approach would be to do something of this sort:
local names = { "Player1", "pmcdonough" } -- Function that checks if a given name is in the names table local function IsValidName(name) -- iterator over the table and compare each value with name for idx = 1, #names do if names[idx] == name then return true -- name is in the table! end end return false -- name is not in the table! end
And then you can check if their name is in the table when needed by doing:
if IsValidName(hum.Parent.Name) then
However there is a more simple approach: use a dictionary!
local names = { ["Player1"] = true, ["pmcdonough"] = true }
And now all you have to do to check if their name is in the table is this:
if names[hum.Parent.Name] then
No function calls, no explicit loops. It's clean, simple, easy to expand. It's beautiful. It's Lua.