Variable differs between server and client?

Im trying to spawn an entity at the safezones position to make sure it isn’t in water, but it spawns the entity at a completely different vector. The variable that defines where it will spawn is set in shared and the safezones location is clientside and the spawning of the water-checker is serverside.

Here is everything in my code related to my issue:

Shared:



zones4 = {
endzone3 + Vector( 0, 0, 0 ),
endzone3 + Vector( 992/1.415, 992/1.415, 0 ),
endzone3 + Vector( -992/1.415, -992/1.415, 0 ),
endzone3 + Vector( -992/1.415, 992/1.415, 0 ),
endzone3 + Vector( 992/1.415, -992/1.415, 0 ),
endzone3 + Vector( 992, 0, 0 ),
endzone3 + Vector( -992, 0, 0 ),
endzone3 + Vector( 0, 992, 0 ),
endzone3 + Vector( 0, -992, 0 )
}
local zone4zone = table.Random(zones4)
endzone4 = zone4zone

local groundhit = util.TraceLine( {
	start = zone4zone+Vector(0,0,5000),
	endpos = zone4zone-Vector(0,0,15000),
	filter = function( ent ) if ( ent:GetClass() == "prop_physics" ) then return true end end
} )

endzone4 = Vector(zone4zone.x,zone4zone.y,groundhit.HitPos.z)-Vector(0,0,100) -- Safezone position


Server:



local watercheck = ents.Create( "prop_physics" )
if ( !IsValid( watercheck ) ) then return end
watercheck:SetModel( "models/props_c17/oildrum001.mdl" )
watercheck:SetPos( endzone4 )
watercheck:Spawn()
if watercheck:WaterLevel() > 0 then
watercheck:Remove()
PrintMessage( HUD_PRINTTALK, "Zone under water, loading new zone." )
GenerateZones()
else
watercheck:Remove()
PrintMessage( HUD_PRINTTALK, "Zone not under water." )
end


Client:



cam.Start3D2D( endzone4, Angle(0,0,0), 1 )
render.SetColorMaterial()

if ply:GetPos():Distance(endzone4) > size4*scale then		
render.DrawSphere( Vector(0,0,0), -size4*scale, poly, poly, Color( 255, 125, 125, 50 ) )
render.DrawSphere( Vector(0,0,0), size4*scale, poly, poly, Color( 255, 125, 125, 50 ) )
else
render.DrawSphere( Vector(0,0,0), -size4*scale, poly, poly, Color( 125, 125, 255, 50 ) )
render.DrawSphere( Vector(0,0,0), size4*scale, poly, poly, Color( 125, 125, 255, 50 ) )
end
cam.End3D2D()


the table.Random in your shared code probably returns different values on server and client

There is no shared state, there is only server and client. If you create a variable on both, although it is called shared, its actually 2 independent variables. You will have to network it if you want to do this.