I was able to implement the equipment and script the abilities no problem.
However, upon unequipping, the object remains in the world. i was wondering as to how to destroy the equipment entirely?
This is the altered script in which i am currently using, any help will be more than appreciated <3
local primaryEquipment = script.parent
function OnEquipped(equipment, player)
if Object.IsValid(player) and player:IsA("Player") then
player.diedEvent:Connect(OnPlayerDied)
oldHealth = player.hitPoints
oldMaxHealth = player.maxHitPoints
player.hitPoints = "150"
player.maxHitPoints = "100"
stillEquiped = true
HealthPlayer(player)
end
end
function OnPlayerDied(player)
for _, equipment in ipairs(player:GetEquipment()) do
equipment:Unequip()
end
end
function HealthPlayer(player)
while Object.IsValid(player) and player:IsA("Player") and stillEquiped do
if player.hitPoints < player.maxHitPoints then
(ADD LINE HERE TO DESTROY OBJECT????)
end
Task.Wait(1)
end
end
primaryEquipment.equippedEvent:Connect(OnEquipped)
I was able to figure out part of my issue was not having the script outside of the client context.
I was able to clean up a bit of the script myself, and i currently receive no errors, however the object just simply wont unequip. I know i'm doing something wrong that is pure obvious, however i am rather new to core and would appreciate any help
My new script:
local Equipment = script.parent
function OnEquipped(Equipment, player)
if Object.IsValid(player) and player:IsA("Player") then
player.hitPoints = "150"
player.maxHitPoints = "100"
currentHealth = player.hitPoints
removeHelm = player.maxHitPoints
remove(player)
end
end
function remove(player)
for _, equipment in ipairs(player:GetEquipment()) do
if player.hitPoints < player.maxHitPoints then
equipment:Unequip()
end
end
end
Equipment.equippedEvent:Connect(OnEquipped)
This is the working solution i was able to come up with. Just had to make sure the asset i used as an equipment was put in a client context, and had to make the "helmet" script, a child of equipment, and not a child of the client context.
local Equipment = script.parent
function OnEquipped(equipment, player)
if Object.IsValid(player) and player:IsA("Player") then
player.damagedEvent:Connect(OnPlayerDamaged)
player.hitPoints = "150"
player.maxHitPoints = "100"
OnPlayerDamaged(player)
end
end
function OnPlayerDamaged(player)
if player.hitPoints < player.maxHitPoints then
Equipment:Destroy()
end
end
Equipment.equippedEvent:Connect(OnEquipped)