In a game that I have been working on, I wanted to add a boss that turns players into zombies by changing the name of their humanoid into "Zombie" and removing their current morph to replace it with a new one, everything seemed to work fine until, as a zombie, I had touched the part that changes players a second time. This, rather than doing nothing to me, had instead turned me invisible. I found that the problem was in the script that removes morphs from players, I had tried to fix this by making it only effect humanoids. To do this, I had tried to add a line to the script to check if the thing touching it was a humanoid... That did not work however, and after fiddling with the script for a while, I had decided that I should come here for help. any help would be very much appreciated, here is the script:
function onTouched(hit) if hit.Parent:findFirstChild("Humanoid") == nil then local d = hit.Parent:GetChildren() for i=1, #d do if (d[i].className == "Model") then d[i]:remove() end end end script.Parent.Touched:connect(onTouched)
I have figured it out myself, and I am putting this hare so that if other people need help with this in the future the answer is here
function onTouched(hit) local h = hit.Parent:FindFirstChild("Humanoid") local d = hit.Parent:GetChildren() for i=1, #d do if (d[i].className == "Model") and h ~= nil then d[i]:remove() end end end script.Parent.Touched:connect(onTouched)