Hello,
I’m trying to create a script that checks the player character model and if it finds the model and the model has these attributes as in the photo below.
I want the Player´s health be same as value of Health attribute in model.
If there is also a ReflexUI attribute, I want to clone the Gui from the replicatedStorage and paste it the into player´s playerGui.
Code:
local Players = game:GetService(“Players”)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local Guis = ReplicatedStorage:WaitForChild(“Guis”)
local character = Players.LocalPlayer.Character
local player = Players:GetPlayerFromCharacter(character)
if not player then return end
local container = character.Parent:FindFirstChild(player.Name)
if not container then return end
for _, model in ipairs(container:GetChildren()) do
if model:IsA(“Model”) then
local healthValue = tonumber(model:GetAttribute(“Health”))
if healthValue then
local humanoid = character:FindFirstChildOfClass(“Humanoid”)
if humanoid then
humanoid.MaxHealth = healthValue
humanoid.Health = healthValue
end
end
local reflexAttr = model:GetAttribute("ReflexUI")
if reflexAttr == true then
local guiTemplate = Guis:FindFirstChild("ReflexGUI")
if guiTemplate then
local guiClone = guiTemplate:Clone()
guiClone:SetAttribute("TargetModel", model.Name)
guiClone.Parent = player:WaitForChild("PlayerGui")
end
end
end
end
Any help would be appreciated.