Sorry for my eventual bad english.
Questions:
-
What do you want to achieve? Understand what is going on.
-
What is the issue? This NPC I made, was created for chasing players. It does not normally go through walls, but when I locally (on client) set a wall’s CanCollide property to false, it is able to go through, even if on server that wall has CanCollide on true.
-
What solutions have you tried so far? I tried messing with the script, but I really have no idea on how to solve this issue.
Chase Script
local ChaseRange = 75
local ai = script.Parent
local AIHumaniod = script.Parent.Humanoid
local AIHumaniodRootPart = script.Parent.HumanoidRootPart
local function GetClosestPlayer()
local closestPlayer = nil
local closestPlayerDistance = ChaseRange
for i,v in pairs(game.Players:GetPlayers())do
if v.Character then
local charHRP = v.Character.HumanoidRootPart
if (charHRP.Position-AIHumaniodRootPart.Position).Magnitude < closestPlayerDistance then -- Checks if player has a body. --
closestPlayer = v.Character
closestPlayerDistance = (charHRP.Position-AIHumaniodRootPart.Position).Magnitude
end
end
end
return closestPlayer
end
local counter = 0
while true do
wait(1)
local ClosestPlayer = GetClosestPlayer()
if ClosestPlayer then
AIHumaniod:MoveTo(ClosestPlayer.HumanoidRootPart.Position)
end
if ClosestPlayer == nil then
counter += 1
print(counter)
if counter > 9 then
AIHumaniodRootPart.CFrame = game.Workspace.coooool.CFrame
counter = 0
end
end
end
for _, zambieparts in pairs(ai:GetChildren()) do
if zambieparts:IsA'Part' then
zambieparts.Touched:connect(function(p)
if p.Parent.Name == GetPlayerNames() and p.Parent.Name ~= ai.Name then -- damage
local enemy = p.Parent
local enemyhuman = getHumanoid(enemy)
enemyhuman:TakeDamage(999)
end
end)
end
end
function GetPlayerNames()
local players = game:GetService('Players'):GetChildren()
local name = nil
for _, v in pairs(players) do
if v:IsA'Player' then
name = tostring(v.Name)
end
end
return name
end
function getHumanoid(model)
for _, v in pairs(model:GetChildren()) do
if v:IsA'Humanoid' then
return v
end
end
end
Door Opener Script
local event = game.ReplicatedStorage.keys
wait(2)
-- Locals
local doorRed = game.Workspace:WaitForChild("Red")
local doorBlue = game.Workspace.Blue
local doorGreen = game.Workspace.Green
local buttRed = game.Workspace.Keys.KeyRed
local buttBlue = game.Workspace.Keys.KeyBlue
local buttGreen = game.Workspace.Keys.KeyGreen
local sound = script:WaitForChild("pick sound")
local soundCD = 2
local canSound = true
-- Doors settings
doorRed.Transparency = 0
doorRed.CanCollide = true
doorBlue.Transparency = 0
doorBlue.CanCollide = true
doorGreen.Transparency = 0
doorGreen.CanCollide = true
-- Keys settings
buttRed.Transparency = 0
buttBlue.Transparency = 0
buttGreen.Transparency = 0
event.OnClientEvent:Connect(function(color)
if canSound == true then
sound:Play()
canSound = false
wait(soundCD)
canSound = true
else
end
if color == "green" then
doorGreen.Transparency = 0.75
doorGreen.CanCollide = false
buttGreen.Transparency = 0.75
elseif color == "blue" then
doorBlue.Transparency = 0.75
doorBlue.CanCollide = false
buttBlue.Transparency = 0.75
elseif color == "red" then
doorRed.Transparency = 0.75
doorRed.CanCollide = false
buttRed.Transparency = 0.75
end
end)
Video demonstrating what is happening