✓ Accepted answer
Hello Julianhak06,
I recommend using a normal script so the changes can replicate to the server, as well as using UserIDs instead of their name, so if they change their name, you won't have to update the script. In my example, we will be using a table and using a for loop to get the contents in that table.
local Players = game:GetService('Players')
local SetHealth = 500
local AllowedIDs = {
1,
2,
}
Players.PlayerAdded:Connect(function(player)
local canSetHealth = false
for index, id in pairs(AllowedIDs) do
if player.userId == id then
canSetHealth = true
end
end
if canSetHealth then
player.CharacterAdded:Connect(function(character)
character:WaitForChild('Humanoid')
character.Humanoid.MaxHealth = SetHealth
character.Humanoid.Health = SetHealth
end)
end
end)
GetRankInGroup (https://developer.roblox.com/en-us/api-reference/function/Player/GetRankInGroup)
local Players = game:GetService('Players')
local GroupID = GROUPID
local RankAllowed = RANKID
Players.PlayerAdded:Connect(function(player)
if player:GetRankInGroup(GroupID) >= RankAllowed then
player.CharacterAdded:Connect(function(character)
character:WaitForChild('Humanoid')
character.Humanoid.MaxHealth = SetHealth
character.Humanoid.Health = SetHealth
end)
end
end)
IsInGroup (https://developer.roblox.com/en-us/api-reference/function/Player/IsInGroup)
local Players = game:GetService('Players')
local GroupID = GROUPID
Players.PlayerAdded:Connect(function(player)
if player:IsInGroup(GroupID) then
player.CharacterAdded:Connect(function(character)
character:WaitForChild('Humanoid')
character.Humanoid.MaxHealth = SetHealth
character.Humanoid.Health = SetHealth
end)
end
end)
4 comments
Works like a charm, thanks! But how could I set it for a group, for example?
You could use the Player:IsInGroup() or Player:GetRankInGroup() method. I will edit my answer with both in a few.
Thanks! Have a good day.
You as well! :D