#Trying to add a function where if you reach below 50 health, accessories change

1 messages · Page 1 of 1 (latest)

worn scroll
#

`local player = game.Players.LocalPlayer
local character = script.Parent
local humanoid = character:FindFirstChild("Humanoid")
local root = character:FindFirstChild("HumanoidRootPart")
local idleAnimation = game.ReplicatedStorage:FindFirstChild("LowHealthIdleAnimation")
local walkAnimation = game.ReplicatedStorage:FindFirstChild("LowHealthWalkAnimation")
local loadedIdleAnimation = humanoid:LoadAnimation(idleAnimation)
local loadedWalkAnimation = humanoid:LoadAnimation(walkAnimation)

local moodFace = game.ReplicatedStorage.Accessories.UziMoody
local angryFace = game.ReplicatedStorage.Accessories.UziAngry
local below50 = false

local function getAccessoryByName(char, name)
for _, accessory in ipairs(char:GetChildren()) do
if accessory:IsA("Accessory") and accessory.Name == name then
return accessory
end
end
end

local function updateAccessory()
if humanoid.Health <= 50 and not below50 then

    moodFace = getAccessoryByName(character, "NormalAccessory")
    if moodFace then moodFace:Destroy() end
    
    if not getAccessoryByName(character, "LowHealthAccessory") then
        local newAcc = game.ServerStorage:FindFirstChild("LowHealthAccessory"):Clone()
        newAcc.Name = "LowHealthAccessory"
        newAcc.Parent = character
        character.Humanoid:AddAccessory(newAcc)
    end
    
    below50 = true
    
elseif humanoid.Health > 50 and below50 then
    
    angryFace = getAccessoryByName(character, "LowHealthAccessory")
    if angryFace then angryFace:Destroy() end
    
    if not getAccessoryByName(character, "NormalAccessory") then
        local newAcc = game.ServerStorage:FindFirstChild("NormalAccessory"):Clone()
        newAcc.Name = "NormalAccessory"
        newAcc.Parent = character
        character.Humanoid:AddAccessory(newAcc)
    end
    
    below50 = false
 end

end

humanoid:GetPropertyChangedSignal("Health"):Connect(updateAccessory)

updateAccessory()`

dull sailBOT
#

studio** You are now Level 5! **studio

worn scroll
#

This error comes up Workspace.DarkLordKilla94.Health:53: attempt to index nil with 'Clone'

hollow rune
dull sailBOT
#

studio** You are now Level 1! **studio

hollow rune
#

U can do one of these options:

  1. Make it in a server
  2. use ReplicatedStorage
worn scroll
#

The accessories are in Replicated Storage !

hollow rune
#

U literally wrote game.Serverstorage:clone()

worn scroll
#

Im a little bit stupid..

#

I changed it but the error is still there

hollow rune
#

The same error?

worn scroll
#

Yeppety yep

hollow rune
#

Damn idk

#

Just ask chatgpt

#

send him the new script and error

worn scroll
#

Oh oki

celest merlin
#

dont do that

#

you wont learn