ok so when an npc’s health gets lower than 50, a proximity prompt appears on the npc and if you activate it, all the npc’s accessories get transported to you and then the npc is destroyed. If you decide to help me, please include a screenshot of your explorer. this is the scripts i made and don’t work:
(keep in mind that even if the npc health is below 50, the proximity prompt doesn’t show up so i haven’t tested the script inside of the prompt yet.)
script in server script service:
local dummy = game.Workspace.Dummy
if dummy.Humanoid.Health <= 50 then
dummy.ProximityPrompt.Enabled = true
end
this script works if i automatically set the npc health to 50, but not if it’s at 100 and i use my sword to make it below 50.
this is the script inside of the proximity prompt (can u help me make it so that it takes everything inside the dummy that’s an accessory)
script.Parent.Triggered:Connect(function(plr)
script.Parent.Parent.Horns:Clone().Parent = plr.Character
wait(1)
script.Parent.Parent:Destroy()
end
I think that last script you showed is invalid, because there should be a “)” after the end keyword in the last word. If you’re trying to check if the health is under 50, I recommend using :GetPropertyChangedSignal() function event. Whenever it fires, check if it’s under or equal to 50. If so, add the proximity prompt, and check when it’s activated. you can then add the items there. Here’s an example if you don’t understand.
local dummy = game.Workspace.Dummy
dummy.Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
if dummy.Humanoid.Health <= 50 then
-- add proximity prompt and triggered event
dummy.ProximityPrompt.Enabled = true
dummy.ProximityPrompt.Triggered:Connect(function(plr)
-- add items here.
end)
end
end)
This script should be in serverscriptservice, or workspace. Also, make sure the proximityprompt is inside of the dummy. I’m kind of confused with the fact that you just used a simple if statement to check if the health was less than 50, unless you only need to check once.
if dummy.Humanoid.Health <= 50 then
dummy.ProximityPrompt.Enabled = true
end
you should put a while true do so that it continuously checks the NPC’s health
while true do
wait() -- make sure you put the "wait()" there or else it will crash the game
if dummy.Humanoid.Health <= 50 then
dummy.ProximityPrompt.Enabled = true
end
end
You already have. Use the script I showed you. If you want to disable it when the dummies’ health goes above 50, just use else and disable it. I’m 99% percent sure this script should work.
local dummy = game.Workspace.Dummy
dummy.Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
if dummy.Humanoid.Health <= 50 then
-- add proximity prompt and triggered event
dummy.ProximityPrompt.Enabled = true
dummy.ProximityPrompt.Triggered:Connect(function(plr)
-- add items here.
end)
end
end)
You may have to disconnect previous events, though.