Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Zombies arent getting unanchored on part touch?

Asked by 2 years ago

I was trying to create a script where when you touch a part the zombies would get unanchored. However, it didn't work. there were no red lines in the script. No errors were in the output menu So im not sure why its not working

The Code (Server Script)

local zombies = game.Workspace.MainMap.Stage1Z.SZ1:GetChildren()
local part = game.Workspace.MainMap.UnAnchors.Part

function ZombieAnchor()
    zombies.Anchored = false
end

part.Touched:Connect(ZombieAnchor)


Please Help its not working

2 answers

Log in to vote
0
Answered by
vileras 22
2 years ago
Edited 2 years ago

Try This:

script.Parent.Touched:Connect(function(hit)
   local human = hit.Parent:FindFirstChild("Humanoid")
    if (human ~= nil) then --Will detect only characters instead of parts ect
            zombies.Anchored = false
      end
end)
Ad
Log in to vote
0
Answered by 2 years ago

You cant just set multiple values to unanchored at once. You can use a loop to get all the parts and set them to unanchored individually.

local zombies = game.Workspace.MainMap.Stage1Z.SZ1:GetChildren()
local part = game.Workspace.MainMap.UnAnchors.Part

function ZombieAnchor()
    for i, v in ipairs(zombies) -- loop through all the parts
        if v:IsA("BasePart") then -- check if it is basepart so it can be anchored
            v.Anchored = false
        end
    end
end

part.Touched:Connect(ZombieAnchor)

Answer this question