script.Parent.AncestryChanged:Connect(function(child, parent)
if parent == game.Players.LocalPlayer.PlayerGui.talking then
local npc = game.Workspace:FindFirstChild(script.Parent.npcName.Value)--could error because the value might not have changed yet and might be nil
print("NPC'S NAME IS "..npc.Name)
local property = npc.Humanoid.Health
while wait() do
if property <= 0 then
game.Players.LocalPlayer.Character.Humanoid.AutoRotate = true
game.Players.LocalPlayer.Character.HumanoidRootPart.Anchored = false
game.ReplicatedStorage.changeTalkValue:FireServer(false)
script.Parent:Destroy()
end
end
end
end)
the above script is a local script, inside server storage
it is supposed to-
check if its ancestry changed
if it has, check if it is in the right place
if it is, then create a variable for the npc’s name (ive checked on client side, the value does seem to change)
then create a variable for its health, then loop constantly checking if the health is 0
but that print statement? it never runs
which makes me assume that when i clone this (which is what im doing) and parent it, it doesnt count as triggering ancestry changed
in which case, how do i stop it from running until its inside the player gui? if i say
while wait() do
if script.Parent.Parent == game.Players.LocalPlayer.PlayerGui.Talking then
wouldnt that error? Because since its in server storage, it doesnt know what the local player is…?
or, does the local script just not run in the server storage, in which case, i dont need any ancestry changed event at all, and itll only run when i put it in a local area?
i mightve phrased a lot of this poorly, if youre confused ill try to answer any questions