Hello Devs mind if yall help me fix this wired thing!
from the video the ground is client-side but the npc is server-side mean that he cant see client-side but server-side then just noclip through the ground me and my friend tried fix this thing for some days but never works ( and yea the red highlight thing is the npc)
sorry i kinda bad at explaining stuff like this (also grammar) this my first time on making a real game
Thanks
[REPOST #1]
What did you expect?
Server doesnât see the ground so the NPC will move through it.
What do you want to achieve by this? Why isnât the ground on server as well?
local floor = math.floor
local abs = math.abs
local wait = wait
local ipairs = ipairs
local insert table.insert
local Chunk = require(game.ReplicatedStorage.Chunk)
local WIDTH_SCALE = Chunk.WIDTH_SCALE
local X, Z = Chunk.X, Chunk.Z
local CHUNKS_LOADED_PER_TICK = 5
local TICKS_PER_UPDATE_CYCLE = 30
local RENDER_DISTANCE = 16
local cameraChunkPosX
local cameraChunkPosZ
local loadedChunkPosX
local loadedChunkPosZ
local fastLoad = true
local chunkCount = 0
local updateCount = 0
local chunks = {}
local function getChunkPosFromCamera()
local camPos = Vector3.new(0, 0, 0) -- replace with NPC position
local camX = camPos.X
local camZ = camPos.Z
return
floor((camX - WIDTH_SCALE) / ((X-1) * WIDTH_SCALE)),
floor((camZ - WIDTH_SCALE) / ((Z-1) * WIDTH_SCALE))
end
local function isCamChunkPosOutOfLoadedChunkRange()
if (loadedChunkPosX == nil or loadedChunkPosZ == nil)
or (abs(cameraChunkPosX - loadedChunkPosX) >= RENDER_DISTANCE)
or (abs(cameraChunkPosZ - loadedChunkPosZ) >= RENDER_DISTANCE) then
return true
else
return false
end
end
local function destroyDistantChunks()
local n = #chunks
for i = 1, n do
if abs(chunks[i].x - cameraChunkPosX) > RENDER_DISTANCE
or abs(chunks[i].z - cameraChunkPosZ) > RENDER_DISTANCE then
chunkCount = (chunkCount + 1) % CHUNKS_LOADED_PER_TICK
if (chunkCount == 0) and (not fastLoad) then
wait()
end
chunks[i]:Destroy()
chunks[i] = nil
end
end
local j = 0
for i = 1, n do
if chunks[i] ~= nil then
j = j + 1
chunks[j] = chunks[i]
end
end
for i = j + 1, n do
chunks[i] = nil
end
end
local function renderChunks()
for x = cameraChunkPosX - RENDER_DISTANCE, cameraChunkPosX + RENDER_DISTANCE do
for z = cameraChunkPosZ - RENDER_DISTANCE, cameraChunkPosZ + RENDER_DISTANCE do
local chunkExists = false
for index, chunk in ipairs(chunks) do
if chunk.x == x and chunk.z == z then
chunkExists = true
break
end
end
if not chunkExists then
chunkCount = (chunkCount + 1) % CHUNKS_LOADED_PER_TICK
if (chunkCount == 0) and (not fastLoad) then
wait()
end
insert(chunks, Chunk.new(x, z))
end
end
end
end
local function updateTerrain()
destroyDistantChunks()
renderChunks()
loadedChunkPosX = cameraChunkPosX
loadedChunkPosZ = cameraChunkPosZ
end
while true do
cameraChunkPosX, cameraChunkPosZ = getChunkPosFromCamera()
if isCamChunkPosOutOfLoadedChunkRange() then
fastLoad = true
else
fastLoad = false
end
if (updateCount == 0) or (fast) then
updateTerrain()
end
updateCount = (updateCount + 1) % TICKS_PER_UPDATE_CYCLE
wait()
end
i think this is it (yea i totally stole it it is inf terrain gen)
Ok, so what you need to do is instead of having the terrain script client side (i.e in a local script) you need to build it server side (i.e. in âscriptâ.) otherwise the npc wont be able to see it
right you have a chunk system that works server side. Im not sure if you would be able to have npcâs there, i think your best bet is to have the npcs client side (spawn them in via local script)
otherwise i have no idea